26.7. 例子
将键/值放在命名的缓存中:
from("direct:start") .setHeader(InfinispanConstants.OPERATION).constant(InfinispanOperation.PUT) (1) .setHeader(InfinispanConstants.KEY).constant("123") (2) .to("infinispan:myCacheName&cacheContainer=#cacheContainer"); (3)
from("direct:start") .setHeader(InfinispanConstants.OPERATION).constant(InfinispanOperation.PUT) (1) .setHeader(InfinispanConstants.KEY).constant("123") (2) .to("infinispan:myCacheName&cacheContainer=#cacheContainer"); (3)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 其中,
- 1 - 设置要执行的操作
- 2 - 设置用于识别缓存中元素的密钥
3 - 使用 registry 中配置的缓存管理器
cacheContainer
将元素放在名为myCacheName
的缓存中可以在条目过期前配置生命周期和/或空闲时间,并从缓存中驱除,例如:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
其中,
- 1 - 设置条目的寿命
- 2 - 为 lifespan 设置时间单位
queries
注意
域对象的 .proto 描述符必须注册到远程 Data Grid 服务器,请参阅官方 Infinispan 文档中的 Remote Query Example。
自定义 Listeners
from("infinispan://?cacheContainer=#cacheManager&customListener=#myCustomListener") .to("mock:result");
from("infinispan://?cacheContainer=#cacheManager&customListener=#myCustomListener")
.to("mock:result");
myCustomListener
实例必须存在,Camel 应该可以从 Registry
中查找它。我们鼓励用户扩展 org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener
类,并使用 @ClientListener
标注生成的类,该类可以在 org.infinispan.client.hotrod.annotation
中找到。