How to remotely view and edit Infinispan cached data

I have an Infinispan cache built into the WildFly 8.2 server.

I added to standalone.xml inside <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 entered the cache container as follows:

 @Singleton @Startup public class CacheManager { @Resource(lookup = "java:jboss/infinispan/container/mycache") private CacheContainer container; . . . . } 

I can use cache in my applications.

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

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

jconsole screen

How can I access the cache remotely?

+6
source share
1 answer

First of all, my condolences are that you need to choose a road that traveled less.

It is possible to access the built-in Infinispan cache remotely. You need to configure org.infinispan.server.hotrod.HotRodServer in your server process, essentially redesigning the pre-packaged Infinispan Server distribution. This approach is not documented, so act at your own risk .

You need these dependencies:

 <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> 

Set up an example cache ( infinispan.xml ):

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

Server process:

 // 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 

Client process:

 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 
+4
source

Source: https://habr.com/ru/post/984879/


All Articles