INTRODUCTION

Nowadays, the reality of companies demands even more integration between different technologies, working together, changing, and processing data. In this ecosystem, the use of an integration platform is essential. Still, the use of an in-memory database is necessary for a significant gain in information processing performance. In this article, we will demonstrate the use of the JBoss Fuse integration platform, in conjunction with the In-memory database named  Red Hat Data Grid.

JBoss Fuse is an integration platform based on the framework Apache Camel. It focuses on mediation, transformation, and data routing among many applications, services, and devices.

Red Hat Data Grid, or Datagrid, is an in-memory data management system that uses the concept of key-value based on the open-source product Infinispan. Red Hat Data Grid is usable as a simple cache solution, a NoSql database, or even an event broker. We can assume that Red Hat Data Grid is the enterprise version, and the Infinispan is the community version of the product. This article is about how JBoss Fuse can be used as a middleware solution to communicate with Red Hat Data Grid, being this one configured as a remote cache server.

In the documentation of versions 6.3 and 7.1 of JBoss Fuse, we can find references to a component called camel-jbossdatagrid, which is no longer supported by Red Hat and that has been replaced by the component camel-infinispan in the latest versions.

To demonstrate the integration between JBoss Fuse and Red Hat Data Grid, we created a quickstart project and in this article, we detail how this integration is completed. The source code of this project is available for download at https://git.io/Je1J2.

For this project, we used JBoss Fuse Standalone version 7.4 that uses the Apache Camel 2.21 and Red Hat Data Grid 7.4 that is equivalent to Infinispan version 9.4.

Beyond standalone mode, JBoss Fuse can be executed in the EAP, KARAF, and Openshift. All concepts applied here are compatible with any mode of use.

FIRST STEPS

To connect to Red Hat Data Grid, the first step is to create an instance of an object of type ‘RemoteCacheManager’. This object is responsible for storing the configurations to access the remote server and managing the communication with it.

In the example below, we can visualize the implementation of ‘RemoteCacheManager’ configured in our example project. Basically, it is a java class that uses the class ‘ConfigurationBuilder’ to store the configurations of our Red Hat Data Grid.


Basic methods for this connection are:

With this configuration, the component camel-infinispan is ready to connect and to make operations like insert, read and remove the key in Red Hat Data Grid using the Hot Rod protocol.

This protocol is used to accelerate client access and server interactions faster than other protocols based on text and also allowing clients to make smarter decisions for load balance, failover, and data query.

Before continuing, it is important to understand the syntax of an Infinispan endpoint (Datagrid).  To create producers and consumers, the component uses the following syntax:

To send a key, the URI will be like the example:

In the example above, we are sending data to a remote cache called ‘cacheCustomers’, and the settings required for this submission are in the class called ‘remoteCacheManagerExample’. RemoteCacheManager is the equivalent of a dataSource for JDBC or JPA connections.

Several configuration options can be passed through the URI, and these options can be found on the component's website, within the 'The Apache Software Foundation' portal at https://camel.apache.org/components/latest/infinispan-component.html.

INSERTING A KEY

In our project, we created a webservice that sends a key and value through a JSON object to a route called put-key-route.  This route communicates with Red Hat Data Grid, passing key data that is stored through headers in the Camel message.

When the direct: saveKey route is triggered, it will insert 3 headers into the Camel message informing the type of operation, the name, and the contents of the key.

Below is the implementation of the direct: saveKey route.

In the above implementation, we used constants from the camel-Infinispan component API itself to enter the header's names and even the operation value.

QUERYING A KEY

To query a key in the remote cache, we need to set a header (in Camel route) called ‘CamelInfinispanOperation’ with the value GET, which will inform the remote server that we are making a querying operation. After that, we need to set a second header called ‘CamelInfinispanKey’ with the name of the key to query.

The value of the key is stored in the body of the Camel message. If the key doesn’t exist, the value of the body will be null.

Below, we have a query route of a key.

The key value can be recovered through message body in exchange.getIn().getBody(). No error messages return in case a key is not found in the query.

REMOVING A KEY

A key exclusion follows the same process of the query; we just change the type of operation. In this case, we send a header with the value REMOVE and another header with the key value.

Below, is the route that removes a key in Red Hat Data Grid.

LIFE CYCLE OF A KEY

The properties of LifeSpan e MaxIdle controls the life cycle of a key. These properties are configured during the cache creation inside Red Hat Data Grid; however, it is possible to overwrite the configuration of each key inserted through JBoss Fuse.

LifeSpan is the maximum time that a key remains valid in the cache. If this value is -1, the key never expires. The MaxIdle is the time that a key remains in the cache without being used. LifeSpan should always be higher than MaxIdle.

To set the LifeSpan and MaxIdle values, we use 4 headers.

In the example below, the inserted key will have a 10 seconds lifespan.

FINAL CONSIDERATIONS

JBoss  Fuse and Red Hat Data Grid are powerful tools with a lot of features.  In this article, we talked about basic operations of inserting, getting, and removing keys in a remote cache. However, there are a lot of other features that we can explore, such as local cache, metrics, and advanced queries.

REFERENCES

JBoss Fuse Documentation

https://access.redhat.com/documentation/en-us/red_hat_fuse/7.4/html-single/getting_started/index

componente camel-infinispan Documentation

https://camel.apache.org/components/latest/infinispan-component.html

Infinispan Documentation

https://docs.jboss.org/infinispan/9.4/apidocs/

Red Hat Data Grid Documentation

https://access.redhat.com/documentation/en-us/red_hat_data_grid/7.3/html-single/red_hat_data_grid_user_guide

Connect with Red Hat Services
Learn more about Red Hat Consulting
Learn more about Red Hat Training
Join the Red Hat Learning Community
Learn more about Red Hat Certification
Subscribe to the Training Newsletter
Follow Red Hat Services on Twitter
Follow Red Hat Open Innovation Labs on Twitter
Like Red Hat Services on Facebook
Watch Red Hat Training videos on YouTube
Follow Red Hat Certified Professionals on LinkedIn