Making Java objects queryable by Infinispan remote clients
Making Java objects queryable by Infinispan remote clients
The following is a common question amongst Infinispan community users:
How do I make my Java objects queryable by remote clients?
Annotation Method
The simplest way is to take advantage Infinispan Protostream annotations to mark your objects queryable and decide how each object field should be indexed. Example:
Then, the ProtoSchemaBuilder can inspect the annotated class and derive a Google Protocol Buffers schema file from it. Example:
Finally, the schema file needs to be registered in the “___protobuf_metadata” cache:
Although this is by far the easiest way to make your Java objects queryable, this method might not always be viable. For example, you might not be able to modify the Java object classes to add the annotations. For such use cases, a more verbose method is available that does not require modifying the source code of the Java object.
Plain Object Method
For example, given this Java object:
A Protocol Buffers schema must be defined where comments are used to define the object as queryable and decide how each field is indexed:
This method also requires a Protostream message marshaller to be defined which specifies how each field is serialized/deserialized:
This method still requires the Protocol Buffers schema to be registered remotely, but on top of that, the schema and marshaller need to be registered in the client:
Clearly, this second method is a lot more verbose and more laborious when refactoring. If any changes are made to the Java object, the marshaller and Protocol Buffer schema need to also be changed accordingly. This is done automatically in the first method.
Both methods are demonstrated in full in the queryable-pojos demo.
Cheers Galder
Get it, Use it, Ask us!
We’re hard at work on new features, improvements and fixes, so watch this space for more announcements!Please, download and test the latest release.
The source code is hosted on GitHub. If you need to report a bug or request a new feature, look for a similar one on our JIRA issues tracker. If you don’t find any, create a new issue.
If you have questions, are experiencing a bug or want advice on using Infinispan, you can use GitHub discussions. We will do our best to answer you as soon as we can.
The Infinispan community uses Zulip for real-time communications. Join us using either a web-browser or a dedicated application on the Infinispan chat.