4 Replies Latest reply on Jan 25, 2017 8:13 AM by Adrian Nistor

    Error using querying via Hot Rod in Infinispan

    Manuel Franqueira Newbie

      Hi guys.

      I'm implementing a cache solution using Infinispan (version 7.2.3). I'm using hot rod and I have a problem querying.

       

      When I call the getByKey method, I'm getting error "Caused by: org.infinispan.client.hotrod.exceptions.HotRodClientException:Request for message id[5] returned server error (status=0x85): java.lang.RuntimeException: protostream.com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero)." in List<InfinispanObject> list = query.list(); line. Can you help please?

      Please see my code and where I put the proto file.

       

      Thanks.

      infinispan_querying.png

      My code is:

      InfinispanQueryTest.java class

           private void initProperties() throws NumberFormatException, IOException {

        

              ConfigurationBuilder builder = new ConfigurationBuilder();

              builder.addServer().

                      host("srv-infinispan-3.portoeditora.pt").

                      port(11222).

                      marshaller(new ProtoStreamMarshaller()).

                      connectionPool().

                      lifo(true).

                      maxActive(10).

                      maxIdle(10).

                      maxTotal(20).

                      exhaustedAction(ExhaustedAction.CREATE_NEW).

                      timeBetweenEvictionRuns(120000).

                      minEvictableIdleTime(1800000).

                      minIdle(1);

       

       

              remoteCacheManager = new RemoteCacheManager(builder.build());

              cache = remoteCacheManager.getCache();

             

              registerSchemasAndMarshallers();

          }

       

          private void registerSchemasAndMarshallers() throws IOException {

        

          SerializationContext ctx = ProtoStreamMarshaller.getSerializationContext(remoteCacheManager);

          ctx.registerProtoFiles(FileDescriptorSource.fromResources("/protoFile.proto"));

              ctx.registerMarshaller(new InfinispanObjectMarshaller());

                

              ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();

              String memoSchemaFile = protoSchemaBuilder

                      .fileName("/protoFile.proto")

                      .packageName("quickstart")

                      .addClass(InfinispanObject.class)

                      .build(ctx);

               

                 RemoteCache<String, Object> metadataCache = remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);

                 metadataCache.put("/protoFile.proto", memoSchemaFile);

           }

         

          public Object getByKey(String key) throws NumberFormatException, IOException {

       

          initProperties();

        

          QueryFactory qf = Search.getQueryFactory(cache);

          Query query = qf.from(InfinispanObject.class).having("name").like("fra%").toBuilder().build();

       

          List<InfinispanObject> list = query.list();

          System.out.println("Found " + list.size() + " matches:");

        

          for (InfinispanObject p : list) {

                System.out.println(">> " + p);

             }

        

          return list.get(0);

          }

       

      InfinispanObject.java class

      @ProtoMessage(name = "InfinispanObject")

      public class InfinispanObject implements Serializable {

       

        private String name;

       

        @ProtoField(number = 1, required = true)

        public String getName() {

        return name;

        }

       

        public void setName(String name) {

        this.name = name;

        }

      }

       

      InfinispanObjectMarshaller.java class

      public class InfinispanObjectMarshaller implements MessageMarshaller<InfinispanObject> {

        

          @Override

          public String getTypeName() {

             return "quickstart.InfinispanObject";

          }

        

          @Override

          public Class<InfinispanObject> getJavaClass() {

             return InfinispanObject.class;

          }

        

          @Override

          public InfinispanObject readFrom(ProtoStreamReader reader) throws IOException {

             String name = reader.readString("name");

        

             InfinispanObject object = new InfinispanObject();

             object.setName(name);

             return object;

          }

        

          @Override

          public void writeTo(ProtoStreamWriter writer, InfinispanObject object) throws IOException {

             writer.writeString("name", object.getName());

          }

      }

       

      protoFile.proto file

      package quickstart;

       

      message InfinispanObject {     

            required string name = 1;

      }