Suj*_* PS 6 java jboss caching infinispan wildfly-8
我在WildFly 8.2服务器中嵌入了Infinispan缓存.
我在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>
Run Code Online (Sandbox Code Playgroud)
...并像这样注入缓存容器:
@Singleton
@Startup
public class CacheManager {
@Resource(lookup = "java:jboss/infinispan/container/mycache")
private CacheContainer container;
. . . .
}
Run Code Online (Sandbox Code Playgroud)
我可以在我的应用程序中使用缓存.
但是,要求是使用任何缓存监视API远程查看/编辑/删除缓存数据.
通过jconsole我可以看到缓存信息,但不能看到缓存的数据.

如何远程访问缓存?
首先,我对不得不选择人迹罕至的道路表示哀悼。
可以远程访问嵌入式 Infinispan 缓存。您需要org.infinispan.server.hotrod.HotRodServer在您的服务器进程中设置一个,实质上是对预先打包的Infinispan Server发行版进行逆向工程。此方法未记录在案,因此请自行承担风险。
您需要这些依赖项:
<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>
Run Code Online (Sandbox Code Playgroud)
配置示例缓存 ( infinispan.xml):
<infinispan>
<cache-container default-cache="default">
<local-cache name="dumpster">
<compatibility />
</local-cache>
</cache-container>
</infinispan>
Run Code Online (Sandbox Code Playgroud)
服务器进程:
// 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
Run Code Online (Sandbox Code Playgroud)
客户端流程:
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
Run Code Online (Sandbox Code Playgroud)