如何远程查看和编辑Infinispan缓存数据 [英] How to view and edit Infinispan cached data remotely

查看:425
本文介绍了如何远程查看和编辑Infinispan缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WildFly 8.2服务器中嵌入了Infinispan缓存。

I have an Infinispan cache embedded in a WildFly 8.2 server.

我添加到 standalone.xml 里面< subsystem xmlns =urn:jboss:domain:infinispan:2.0>

<cache-container name="mycache" default-cache="cachedb">
    <transport lock-timeout="600000" />
    <replicated-cache name="cachedb" batching="true" mode="SYNC" />
</cache-container>

...并像这样注入缓存容器:

...and injected the cache container like this:

@Singleton
@Startup
public class CacheManager {

    @Resource(lookup = "java:jboss/infinispan/container/mycache")
    private CacheContainer container;
    . . . . 

}

我可以在我的应用程序中使用缓存。

I can use the cache in my applications.

然而,要求是使用任何缓存监控API远程查看/编辑/删除缓存数据。

However the requirement is to see/edit/delete the cached data remotely by using any of the cache monitoring APIs.

通过jconsole我可以看到缓存信息,但不能看到缓存的数据。

Via jconsole I can see the cache information, but not the cached data.

如何远程访问缓存?

推荐答案

首先,我对必须选择较少旅行的道路表示哀悼。

First of all, my condolences on having to choose the road less traveled.

可以远程访问嵌入式Infinispan缓存。您需要在服务器进程中设置 org.infinispan.server.hotrod.HotRodServer ,实质上是对预先打包的 Infinispan Server 发行版。 此方法未记录,因此请自担风险

It's possible to access an embedded Infinispan cache remotely. You need to set up a org.infinispan.server.hotrod.HotRodServer in your server process, essentially reverse engineering the pre-packaged Infinispan Server distribution. This approach is not documented, so proceed at your own risk.

您需要这些依赖项:

<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-server-hotrod</artifactId>
    <version>7.1.0.Final</version>
</dependency>
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-client-hotrod</artifactId>
    <version>7.1.0.Final</version>
</dependency>
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-remote-query-server</artifactId>
    <version>7.1.0.Final</version>
</dependency>

配置示例缓存( infinispan.xml ):

<infinispan>
    <cache-container default-cache="default">
        <local-cache name="dumpster">
            <compatibility />
        </local-cache>
    </cache-container>
</infinispan>

服务器流程:

// Start a cache manager as usual
EmbeddedCacheManager cacheManager;
try (InputStream in = ClassLoader.getSystemResourceAsStream("infinispan.xml")) {
    cacheManager = new DefaultCacheManager(in);
}

// Start a server to allow remote access to the cache manager
HotRodServerConfiguration serverConfig = new HotRodServerConfigurationBuilder()
        .host("127.0.0.1").port(9999).build();
HotRodServer server = new HotRodServer();
server.start(serverConfig, cacheManager);

// Start the example cache
Cache<String, String> cache = cacheManager.getCache("dumpster", true);
cache.put("K", "V");
System.out.println(cache.get("K")); // V

客户流程:

Configuration config = new ConfigurationBuilder().addServer()
        .host("127.0.0.1").port(9999).build();
RemoteCacheManager cacheManager = new RemoteCacheManager(config);
RemoteCache<String, String> cache = cacheManager.getCache("dumpster");
System.out.println(cache.get("K")); // V

这篇关于如何远程查看和编辑Infinispan缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆