【问题标题】:Infinispan remote query server marshaller issueInfinispan 远程查询服务器编组器问题
【发布时间】:2015-09-25 02:59:10
【问题描述】:

我正在使用 Infinispan 7.0.2.Final,但我的行为非常奇怪。

我正在使用 infinispan 进行服务器和客户端之间的远程查询,使用 infinispan DSL 进行查询,由于某种原因服务器不返回结果列表,但结果大小不为零。

我正在谈论的行为在以下代码中表示。执行以下代码后:

    Query query = qf.from(CacheEntity.class).having("ID").like("%AI%").toBuilder().build();
    System.out.println("size: "+query.getResultSize());
    System.out.println("result: "+query.list());

我得到这个输出:

size: 2000
result: []

这很奇怪,因为结果显然没有 2000 个元素:)

我通过以下方式设置客户端:

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-main.xml");
        RemoteCacheManager manager = ((RemoteCacheManager) context.getBean("cacheManager"));
        
        RemoteCache cache = manager.getCache("cache");
        SerializationContext srcCtx = ProtoStreamMarshaller.getSerializationContext(manager);
        FileDescriptorSource fds = new FileDescriptorSource();
        fds.addProtoFiles("entity.proto");
        srcCtx.registerProtoFiles(fds);

        srcCtx.registerMarshaller(new CachedEntityMarshaller());

        RemoteCache<String, String> metadataCache = manager.getCache("___protobuf_metadata");
        metadataCache.put("entity.proto", new InfinispanClientApplication().read("/entity.proto"));
        MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller.getSerializationContext(manager));

服务器端:

     HotRodServerConfiguration build = new HotRodServerConfigurationBuilder().
             host("127.0.0.1").
             port(11222).
             build(); 
        HotRodServer server = new HotRodServer();        
        server.start(build, cacheManager);

我还注意到,我的 EntityMarshaller 上的 writeTo 方法在每次写入时都会被调用,但 readTo 方法永远不会被调用。

我目前卡住了,我们将不胜感激。

非常感谢!

解决方案:

除了“最佳答案”回复。我正在使用 spring (SpringEmbeddedCacheManagerFactoryBean) 配置我的 infinispan 缓存。我使用 org.infinispan.configuration 类迁移到 java config。之后,我按照“最佳答案”中的建议做了,彻底解决了问题。

【问题讨论】:

    标签: java infinispan


    【解决方案1】:

    我不确定这是否真的是您遇到问题的原因,但启动独立 HotRodServer 时的一个常见问题是您没有正确指定数据容器等效函数:

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.dataContainer()
         .keyEquivalence(new AnyServerEquivalence())
         .valueEquivalence(new AnyServerEquivalence());
    cacheManager.defineConfiguration("cache", builder.build());
    

    请确保您为此缓存使用上述代码。

    【讨论】:

    • 非常感谢!我使用 org.infinispan.configuration 类迁移到 java config,并按照您的建议进行操作,并且成功了!
    猜你喜欢
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 2016-06-21
    • 2013-11-12
    相关资源
    最近更新 更多