45.9. 使用基于 Infinispan 的幂等存储库
在本节中,我们将使用基于 Infinispan 的幂等存储库。
Java 示例
InfinispanRemoteConfiguration conf = new InfinispanRemoteConfiguration(); (1)
conf.setHosts("localhost:1122")
InfinispanRemoteIdempotentRepository repo = new InfinispanRemoteIdempotentRepository("idempotent"); (2)
repo.setConfiguration(conf);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("direct:start")
.idempotentConsumer(header("MessageID"), repo) (3)
.to("mock:result");
}
});
其中,
- 1 - 配置缓存
- 2 - 配置存储库 bean
- 3 - 将存储库设置为路由
XML 示例
<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.remote.InfinispanRemoteIdempotentRepository" destroy-method="stop">
<constructor-arg value="idempotent"/> (1)
<property name="configuration"> (2)
<bean class="org.apache.camel.component.infinispan.remote.InfinispanRemoteConfiguration">
<property name="hosts" value="localhost:11222"/>
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<idempotentConsumer messageIdRepositoryRef="infinispanRepo"> (3)
<header>MessageID</header>
<to uri="mock:result" />
</idempotentConsumer>
</route>
</camelContext>
其中,
- 1 - 设置存储库将使用的缓存名称
- 2 - 配置存储库 bean
- 3 - 将存储库设置为路由