51.10. Infinispan ベースの集計リポジトリーの使用
Java の例
InfinispanEmbeddedConfiguration conf = new InfinispanEmbeddedConfiguration(); (1)
conf.setConfigurationUri("classpath:infinispan.xml")
InfinispanEmbeddedAggregationRepository repo = new InfinispanEmbeddedAggregationRepository("aggregation"); (2)
repo.setConfiguration(conf);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("direct:start")
.aggregate(header("MessageID"))
.completionSize(3)
.aggregationRepository(repo) (3)
.aggregationStrategy("myStrategy")
.to("mock:result");
}
});
- キャッシュを設定します。
- リポジトリー Bean を作成します。
- リポジトリーをルートに設定します。
XML の例
<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedAggregationRepository" destroy-method="stop">
<constructor-arg value="aggregation"/> (1)
<property name="configuration"> (2)
<bean class="org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedConfiguration">
<property name="configurationUrl" value="classpath:infinispan.xml"/>
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<aggregate aggregationStrategy="myStrategy"
completionSize="3"
aggregationRepository="infinispanRepo"> (3)
<correlationExpression>
<header>MessageID</header>
</correlationExpression>
<to uri="mock:result"/>
</aggregate>
</route>
</camelContext>
- リポジトリーで使用されるキャッシュの名前を設定します。
- リポジトリー Bean を設定します。
- リポジトリーをルートに設定します。
注記
Infinispan 11 のリリースでは、作成されたキャッシュにエンコーディング設定を設定する必要があります。これは、イベントを消費する場合にも重要です。詳細は、公式の Infinispan ドキュメントの Data Encoding と MediaTypes を参照してください。