此内容没有您所选择的语言版本。

5.3. Remote Query


When executing remote queries the cacheManager must be an instance of RemoteCacheManager, and an example configuration utilizing a RemoteCacheManager is found below for both Java and blueprint.xml:
Using only Java

from("direct:start")
    .setHeader(InfinispanConstants.OPERATION, InfinispanConstants.QUERY)
    .setHeader(InfinispanConstants.QUERY_BUILDER,
      new InfinispanQueryBuilder() {
        public Query build(QueryFactory<Query> queryFactory) {
          return queryFactory.from(User.class).having("name").like("%abc%")
                      .toBuilder().build();
        }
      })
    .to("infinispan://localhost?cacheContainer=#cacheManager&cacheName=remote_query_cache") ;
Copy to Clipboard Toggle word wrap

Using Blueprint and Java

Java RemoteCacheManagerFactory class:

public class RemoteCacheManagerFactory {      
    ConfigurationBuilder clientBuilder;
    public RemoteCacheManagerFactory(String hostname, int port) {
        clientBuilder = new ConfigurationBuilder();
        clientBuilder.addServer()
            .host(hostname).port(port);
    }
    public RemoteCacheManager newRemoteCacheManager() {
        return new RemoteCacheManager(clientBuilder.build());
    }
}
Copy to Clipboard Toggle word wrap
Java InfinispanQueryExample class:
public class InfinispanQueryExample {
    public InfinispanQueryBuilder getBuilder() {
        return new InfinispanQueryBuilder() {
            public Query build(QueryFactory<Query> queryFactory) {
                return queryFactory.from(User.class)
                         .having("name")
                         .like("%abc%")
                         .toBuilder().build();
            }
        }
    }
}
Copy to Clipboard Toggle word wrap
blueprint.xml:
<bean id=”remoteCacheManagerFactory” class=“com.jboss.datagrid.RemoteCacheManagerFactory”>  
    <argument value=”localhost”/>      
    <argument value="11222”/>      
</bean>
 
<bean id=”cacheManager”
    factory-ref=”remoteCacheManagerFactory” 
    factory-method=“newRemoteCacheManager”>   
</bean>

<bean id="queryBuilder" class="org.example.com.InfinispanQueryExample"/>

<camelContext id="route" xmlns="http://camel.apache.org/schema/blueprint">
    <route>
        <from uri="direct:start"/>
            <setHeader headerName="CamelInfinispanOperation">
                <constant>CamelInfinispanOperationQuery</constant>
            </setHeader>
            <setHeader headerName="CamelInfinispanQueryBuilder">
                <method ref="queryBuilder" method="getBuilder"/>
            </setHeader>
        <to uri="infinispan://localhost?cacheContainer=#cacheManager&cacheName=remote_query_cache"/>
    </route>
</camelContext>
Copy to Clipboard Toggle word wrap

The remote_query_cache is an arbitrary name for a cache that holds the data, and the results of the query will be a list of domain objects stored as a CamelInfinispanOperationResult header.
In addition, there are the following requirements:
  • The RemoteCacheManager must be configured to use ProtoStreamMarshaller.
  • The ProtoStreamMarshaller must be registered with the RemoteCacheManager's serialization context.
  • The .proto descriptors for domain objects must be registered with the remote JBoss Data Grid server.
For more details on how to setup a RemoteCacheManager, see the Remote Querying section of the Red Hat JBoss Data Grid Infinispan Query Guide.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat