Camel Components

Infinispan

Since Camel 2.13

Both producer and consumer are supported

This component allows you to interact with Infinispan distributed data grid / cache using the Hot Rod protocol. Infinispan is an extremely scalable, highly available key/value data store and data grid platform written in Java.

If you use Maven, you must add the following dependency to your pom.xml:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-infinispan</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

infinispan://cacheName?[options]

The producer allows sending messages to a remote cache using the HotRod protocol. The consumer allows listening for events from a remote cache using the HotRod protocol.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Infinispan component supports the following options which are listed below.

Name Description Default Type

configuration (common)

The configuration of the component, which each endpoint copies and then changes with its own options.

InfinispanRemoteConfiguration

hosts (common)

The Hot Rod servers to connect to, as host or host:port separated by semicolons, for example server1:11222;server2:11222. The port defaults to 11222. Required unless cacheContainer or cacheContainerConfiguration is set, and not used then.

String

queryBuilder (common)

To use a custom org.apache.camel.component.infinispan.InfinispanQueryBuilder that builds the query of the QUERY operation of the producer, which the CamelInfinispanQueryBuilder header replaces. When set, the consumer registers a continuous query instead of a listener, and receives the CacheEntryJoining, CacheEntryUpdated and CacheEntryLeaving events of the entries that match the query.

InfinispanQueryBuilder

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

customListener (consumer)

To use a custom listener, a subclass of org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener annotated with the Hot Rod ClientListener annotation, that the consumer registers on the cache in place of its own listener. The eventTypes option is not used then. Not used when queryBuilder is set.

InfinispanRemoteCustomListener

eventTypes (consumer)

The comma-separated names of the Hot Rod client event types that the consumer passes on to the route: CLIENT_CACHE_ENTRY_CREATED, CLIENT_CACHE_ENTRY_MODIFIED, CLIENT_CACHE_ENTRY_REMOVED, CLIENT_CACHE_ENTRY_EXPIRED and CLIENT_CACHE_FAILOVER. If not set, the consumer passes on all of them. Not used when customListener or queryBuilder is set.

String

defaultValue (producer)

The value that the GETORDEFAULT operation returns when the key is not in the cache. The CamelInfinispanDefaultValue header replaces this option.

Object

key (producer)

The key of the entry for the producer operations that take a key, such as PUT, GET, REMOVE and COMPUTE. When set, it takes precedence over the CamelInfinispanKey header.

Object

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

oldValue (producer)

The value that the REPLACE and REPLACEASYNC operations compare with the current value of the entry, to replace the entry only if they are equal. If not set, an existing entry is replaced whatever its value. The CamelInfinispanOldValue header replaces this option.

Object

operation (producer)

The operation that the producer performs. The CamelInfinispanOperation header replaces this option.

Enum values:

  • PUT

  • PUTASYNC

  • PUTALL

  • PUTALLASYNC

  • PUTIFABSENT

  • PUTIFABSENTASYNC

  • GET

  • GETORDEFAULT

  • CONTAINSKEY

  • CONTAINSVALUE

  • REMOVE

  • REMOVEASYNC

  • REPLACE

  • REPLACEASYNC

  • SIZE

  • CLEAR

  • CLEARASYNC

  • QUERY

  • STATS

  • COMPUTE

  • COMPUTEASYNC

PUT

InfinispanOperation

value (producer)

The value of the entry for the PUT, PUTIFABSENT and REPLACE operations and their ASYNC variants, the value to look for with CONTAINSVALUE, and the value that REMOVE and REMOVEASYNC compare with the current value, to remove the entry only if they are equal. The CamelInfinispanValue header replaces this option.

Object

embeddingStoreDimension (producer (advanced))

The number of dimensions of the vector embeddings, which must be equal to the dimension of the embedding model that creates them. It is used in the schema and the default embeddingStoreTypeName. Required, and greater than 0, when the embedding store is enabled.

int

embeddingStoreDistance (producer (advanced))

The k of the kNN query of the embedding store: the number of nearest embeddings that the QUERY operation returns for the vector query of the infinispan:embeddings transformer.

3

int

embeddingStoreEnabled (producer (advanced))

Whether to set up the embedding store, which stores the vector embeddings of camel-langchain4j-embeddings in the cache and searches them with a kNN query. Camel then requires embeddingStoreDimension, sets the ProtoStream marshaller of the embedding type on the RemoteCacheManager that it creates, and registers the schema of the embedding type (see embeddingStoreRegisterSchema). Only takes effect when camel-langchain4j-embeddings is on the classpath.

true

boolean

embeddingStoreRegisterSchema (producer (advanced))

Whether Camel registers the Protobuf schema of the embedding type on the Infinispan server when it starts. Set it to false when the schema is already registered. Only used when the embedding store is enabled.

true

boolean

embeddingStoreSchemaRegistrationTimeout (producer (advanced))

How long Camel retries, once a second, to register the schema of the embedding type while the Infinispan server is not ready, for example when Camel and the server start at the same time. Camel fails to start when the time runs out.

60s

Duration

embeddingStoreTypeName (producer (advanced))

The name of the Protobuf message type of the embeddings, which the schema, the marshaller and the kNN query use. If not set, it is CamelInfinispanRemoteEmbedding followed by the embeddingStoreDimension, for example CamelInfinispanRemoteEmbedding384.

String

embeddingStoreVectorSimilarity (producer (advanced))

The similarity function of the vector field in the schema of the embedding type, which the kNN query uses to compare the embeddings.

Enum values:

  • L2

  • INNER_PRODUCT

  • MAX_INNER_PRODUCT

  • COSINE

COSINE

VectorSimilarity

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

cacheContainer (advanced)

Autowired To use a custom org.infinispan.client.hotrod.RemoteCacheManager. When set or autowired, Camel does not create a RemoteCacheManager, so the hosts, secure, username, password, saslMechanism, securityRealm, securityServerName, cacheContainerConfiguration, configurationUri and configurationProperties options are not used, and Camel does not stop it.

RemoteCacheManager

cacheContainerConfiguration (advanced)

Autowired The org.infinispan.client.hotrod.configuration.Configuration of the RemoteCacheManager that Camel creates when cacheContainer is not set. When set, the hosts, secure, username, password, saslMechanism, securityRealm, securityServerName, configurationUri and configurationProperties options are not used.

Configuration

configurationProperties (advanced)

Hot Rod client configuration properties for the RemoteCacheManager that Camel creates, for example socket_timeout=15000. The prefix infinispan.client.hotrod. is added to a key that does not have it. They take precedence over the properties of the configurationUri file. Not used when cacheContainer or cacheContainerConfiguration is set.

Map

configurationUri (advanced)

The location of the configuration file of the cache manager that Camel creates, read from the classpath unless it has a prefix such as file:. Not used when cacheContainer or cacheContainerConfiguration is set. For infinispan-embedded it is an Infinispan XML configuration file, read on the component only; for infinispan it is a Hot Rod client properties file.

String

flags (advanced)

A comma-separated list of names of org.infinispan.client.hotrod.Flag, for example FORCE_RETURN_VALUE, that the endpoint applies to each cache that it uses.

String

remappingFunction (advanced)

The java.util.function.BiFunction that the COMPUTE and COMPUTEASYNC operations call with the key and the current value of the entry, or null if there is none, to compute its new value. If the function returns null, the entry is removed.

BiFunction

resultHeader (advanced)

The name of the header in which the producer stores the result of the operation, keeping the message body. If not set, the result replaces the message body. The CamelInfinispanOperationResultHeader header replaces this option.

String

password (security)

The password to authenticate with the Infinispan server. Only used when secure is true.

String

saslMechanism (security)

The SASL mechanism of the authentication, for example SCRAM-SHA-512. If not set, the Hot Rod client uses SCRAM-SHA-256. Only used when secure is true.

String

secure (security)

Whether the Hot Rod client authenticates with the Infinispan server, with the username and password options, which are then required, and the saslMechanism, securityRealm and securityServerName options. Not used when cacheContainer or cacheContainerConfiguration is set.

false

boolean

securityRealm (security)

The name of the security realm of the user. If not set, the Hot Rod client uses default. Only used when secure is true.

String

securityServerName (security)

The server name of the SASL authentication. If not set, the Hot Rod client uses infinispan. Only used when secure is true.

String

username (security)

The username to authenticate with the Infinispan server. Only used when secure is true.

String

Endpoint Options

The Infinispan endpoint is configured using URI syntax:

infinispan:cacheName

With the following path and query parameters:

Path Parameters

Name Description Default Type

cacheName (common)

Required The name of the cache. The value current, or an empty name, uses the default cache of the Infinispan server. The CamelInfinispanCacheName header replaces this name for the producer.

String

Query Parameters

Name Description Default Type

hosts (common)

The Hot Rod servers to connect to, as host or host:port separated by semicolons, for example server1:11222;server2:11222. The port defaults to 11222. Required unless cacheContainer or cacheContainerConfiguration is set, and not used then.

String

queryBuilder (common)

To use a custom org.apache.camel.component.infinispan.InfinispanQueryBuilder that builds the query of the QUERY operation of the producer, which the CamelInfinispanQueryBuilder header replaces. When set, the consumer registers a continuous query instead of a listener, and receives the CacheEntryJoining, CacheEntryUpdated and CacheEntryLeaving events of the entries that match the query.

InfinispanQueryBuilder

customListener (consumer)

To use a custom listener, a subclass of org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener annotated with the Hot Rod ClientListener annotation, that the consumer registers on the cache in place of its own listener. The eventTypes option is not used then. Not used when queryBuilder is set.

InfinispanRemoteCustomListener

eventTypes (consumer)

The comma-separated names of the Hot Rod client event types that the consumer passes on to the route: CLIENT_CACHE_ENTRY_CREATED, CLIENT_CACHE_ENTRY_MODIFIED, CLIENT_CACHE_ENTRY_REMOVED, CLIENT_CACHE_ENTRY_EXPIRED and CLIENT_CACHE_FAILOVER. If not set, the consumer passes on all of them. Not used when customListener or queryBuilder is set.

String

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

defaultValue (producer)

The value that the GETORDEFAULT operation returns when the key is not in the cache. The CamelInfinispanDefaultValue header replaces this option.

Object

key (producer)

The key of the entry for the producer operations that take a key, such as PUT, GET, REMOVE and COMPUTE. When set, it takes precedence over the CamelInfinispanKey header.

Object

oldValue (producer)

The value that the REPLACE and REPLACEASYNC operations compare with the current value of the entry, to replace the entry only if they are equal. If not set, an existing entry is replaced whatever its value. The CamelInfinispanOldValue header replaces this option.

Object

operation (producer)

The operation that the producer performs. The CamelInfinispanOperation header replaces this option.

Enum values:

  • PUT

  • PUTASYNC

  • PUTALL

  • PUTALLASYNC

  • PUTIFABSENT

  • PUTIFABSENTASYNC

  • GET

  • GETORDEFAULT

  • CONTAINSKEY

  • CONTAINSVALUE

  • REMOVE

  • REMOVEASYNC

  • REPLACE

  • REPLACEASYNC

  • SIZE

  • CLEAR

  • CLEARASYNC

  • QUERY

  • STATS

  • COMPUTE

  • COMPUTEASYNC

PUT

InfinispanOperation

value (producer)

The value of the entry for the PUT, PUTIFABSENT and REPLACE operations and their ASYNC variants, the value to look for with CONTAINSVALUE, and the value that REMOVE and REMOVEASYNC compare with the current value, to remove the entry only if they are equal. The CamelInfinispanValue header replaces this option.

Object

embeddingStoreDimension (producer (advanced))

The number of dimensions of the vector embeddings, which must be equal to the dimension of the embedding model that creates them. It is used in the schema and the default embeddingStoreTypeName. Required, and greater than 0, when the embedding store is enabled.

int

embeddingStoreDistance (producer (advanced))

The k of the kNN query of the embedding store: the number of nearest embeddings that the QUERY operation returns for the vector query of the infinispan:embeddings transformer.

3

int

embeddingStoreEnabled (producer (advanced))

Whether to set up the embedding store, which stores the vector embeddings of camel-langchain4j-embeddings in the cache and searches them with a kNN query. Camel then requires embeddingStoreDimension, sets the ProtoStream marshaller of the embedding type on the RemoteCacheManager that it creates, and registers the schema of the embedding type (see embeddingStoreRegisterSchema). Only takes effect when camel-langchain4j-embeddings is on the classpath.

true

boolean

embeddingStoreRegisterSchema (producer (advanced))

Whether Camel registers the Protobuf schema of the embedding type on the Infinispan server when it starts. Set it to false when the schema is already registered. Only used when the embedding store is enabled.

true

boolean

embeddingStoreSchemaRegistrationTimeout (producer (advanced))

How long Camel retries, once a second, to register the schema of the embedding type while the Infinispan server is not ready, for example when Camel and the server start at the same time. Camel fails to start when the time runs out.

60s

Duration

embeddingStoreTypeName (producer (advanced))

The name of the Protobuf message type of the embeddings, which the schema, the marshaller and the kNN query use. If not set, it is CamelInfinispanRemoteEmbedding followed by the embeddingStoreDimension, for example CamelInfinispanRemoteEmbedding384.

String

embeddingStoreVectorSimilarity (producer (advanced))

The similarity function of the vector field in the schema of the embedding type, which the kNN query uses to compare the embeddings.

Enum values:

  • L2

  • INNER_PRODUCT

  • MAX_INNER_PRODUCT

  • COSINE

COSINE

VectorSimilarity

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

cacheContainer (advanced)

Autowired To use a custom org.infinispan.client.hotrod.RemoteCacheManager. When set or autowired, Camel does not create a RemoteCacheManager, so the hosts, secure, username, password, saslMechanism, securityRealm, securityServerName, cacheContainerConfiguration, configurationUri and configurationProperties options are not used, and Camel does not stop it.

RemoteCacheManager

cacheContainerConfiguration (advanced)

Autowired The org.infinispan.client.hotrod.configuration.Configuration of the RemoteCacheManager that Camel creates when cacheContainer is not set. When set, the hosts, secure, username, password, saslMechanism, securityRealm, securityServerName, configurationUri and configurationProperties options are not used.

Configuration

configurationProperties (advanced)

Hot Rod client configuration properties for the RemoteCacheManager that Camel creates, for example socket_timeout=15000. The prefix infinispan.client.hotrod. is added to a key that does not have it. They take precedence over the properties of the configurationUri file. Not used when cacheContainer or cacheContainerConfiguration is set.

Map

configurationUri (advanced)

The location of the configuration file of the cache manager that Camel creates, read from the classpath unless it has a prefix such as file:. Not used when cacheContainer or cacheContainerConfiguration is set. For infinispan-embedded it is an Infinispan XML configuration file, read on the component only; for infinispan it is a Hot Rod client properties file.

String

flags (advanced)

A comma-separated list of names of org.infinispan.client.hotrod.Flag, for example FORCE_RETURN_VALUE, that the endpoint applies to each cache that it uses.

String

remappingFunction (advanced)

The java.util.function.BiFunction that the COMPUTE and COMPUTEASYNC operations call with the key and the current value of the entry, or null if there is none, to compute its new value. If the function returns null, the entry is removed.

BiFunction

resultHeader (advanced)

The name of the header in which the producer stores the result of the operation, keeping the message body. If not set, the result replaces the message body. The CamelInfinispanOperationResultHeader header replaces this option.

String

password (security)

The password to authenticate with the Infinispan server. Only used when secure is true.

String

saslMechanism (security)

The SASL mechanism of the authentication, for example SCRAM-SHA-512. If not set, the Hot Rod client uses SCRAM-SHA-256. Only used when secure is true.

String

secure (security)

Whether the Hot Rod client authenticates with the Infinispan server, with the username and password options, which are then required, and the saslMechanism, securityRealm and securityServerName options. Not used when cacheContainer or cacheContainerConfiguration is set.

false

boolean

securityRealm (security)

The name of the security realm of the user. If not set, the Hot Rod client uses default. Only used when secure is true.

String

securityServerName (security)

The server name of the SASL authentication. If not set, the Hot Rod client uses infinispan. Only used when secure is true.

String

username (security)

The username to authenticate with the Infinispan server. Only used when secure is true.

String

Message Headers

The Infinispan component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelInfinispanEventType (consumer)

Constant: EVENT_TYPE

The type of the event that the consumer received: the name of the Infinispan event type, or CacheEntryJoining, CacheEntryUpdated or CacheEntryLeaving for a continuous query.

String

CamelInfinispanCacheName (common)

Constant: CACHE_NAME

The name of the cache. The consumer sets it for each event, and for the producer it replaces the cache name of the endpoint.

String

CamelInfinispanKey (common)

Constant: KEY

The key of the entry. The consumer sets it for each event that has one. The producer uses it for the operations that take a key, unless the key option is set.

Object

CamelInfinispanValue (producer)

Constant: VALUE

The value of the entry for the producer operations that take a value. It replaces the value option.

Object

CamelInfinispanDefaultValue (producer)

Constant: DEFAULT_VALUE

The value that the GETORDEFAULT operation returns when the key is not in the cache. It replaces the defaultValue option.

Object

CamelInfinispanOldValue (producer)

Constant: OLD_VALUE

The value that the REPLACE and REPLACEASYNC operations compare with the current value of the entry, to replace the entry only if they are equal. It replaces the oldValue option. The consumer of infinispan-embedded sets it to the value of the removed entry for a CACHE_ENTRY_REMOVED event.

Object

CamelInfinispanMap (producer)

Constant: MAP

The java.util.Map of the entries that the PUTALL and PUTALLASYNC operations store.

Map

CamelInfinispanOperation (producer)

Constant: OPERATION

The operation that the producer performs. It replaces the operation option.

Enum values:

  • PUT

  • PUTASYNC

  • PUTALL

  • PUTALLASYNC

  • PUTIFABSENT

  • PUTIFABSENTASYNC

  • GET

  • GETORDEFAULT

  • CONTAINSKEY

  • CONTAINSVALUE

  • REMOVE

  • REMOVEASYNC

  • REPLACE

  • REPLACEASYNC

  • SIZE

  • CLEAR

  • CLEARASYNC

  • QUERY

  • STATS

  • COMPUTE

  • COMPUTEASYNC

InfinispanOperation

CamelInfinispanOperationResult (producer)

Constant: RESULT

Deprecated The name of the header whose value is the result. Deprecation note: Never set nor read by the component. Use CamelInfinispanOperationResultHeader to choose the header that carries the result of an operation.

String

CamelInfinispanOperationResultHeader (producer)

Constant: RESULT_HEADER

The name of the header in which the producer stores the result of the operation, keeping the message body. It replaces the resultHeader option.

String

CamelInfinispanLifespanTime (producer)

Constant: LIFESPAN_TIME

The lifespan of the entry, after which it expires, for the PUT, PUTALL, PUTIFABSENT and REPLACE operations and their ASYNC variants. Only used together with the CamelInfinispanTimeUnit header. A negative value means that the entry does not expire.

long

CamelInfinispanTimeUnit (producer)

Constant: LIFESPAN_TIME_UNIT

The java.util.concurrent.TimeUnit of the CamelInfinispanLifespanTime header.

Enum values:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

TimeUnit

CamelInfinispanMaxIdleTime (producer)

Constant: MAX_IDLE_TIME

The maximum time that the entry can stay without being accessed before it expires, for the same operations as the CamelInfinispanLifespanTime header. Only used together with the CamelInfinispanMaxIdleTimeUnit header, and only when the CamelInfinispanLifespanTime and CamelInfinispanTimeUnit headers are set too.

long

CamelInfinispanMaxIdleTimeUnit (producer)

Constant: MAX_IDLE_TIME_UNIT

The java.util.concurrent.TimeUnit of the CamelInfinispanMaxIdleTime header.

Enum values:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

TimeUnit

CamelInfinispanEventData (consumer)

Constant: EVENT_DATA

The value of the entry that the event is about, when the event carries one. For a continuous query, it is the value of the entry that joins the result or is updated.

Object

CamelInfinispanQueryBuilder (producer)

Constant: QUERY_BUILDER

The org.apache.camel.component.infinispan.InfinispanQueryBuilder that builds the query of the QUERY operation. It replaces the queryBuilder option.

InfinispanQueryBuilder

CamelInfinispanEntryVersion (consumer)

Constant: ENTRY_VERSION

Provides access to the version of the created cache entry.

long

CamelInfinispanCommandRetried (consumer)

Constant: COMMAND_RETRIED

This will be true if the write command that caused this had to be retried again due to a topology change.

boolean

Message Body

The message body at each side of the Infinispan component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

null

No body: the event type, the cache name and the key of the entry are in headers, and for the events of a continuous query (queryBuilder) the value in the CamelInfinispanEventData header.

Not known when customListener is set.

Producer input

any

The body is not used: the key, the value and the Map for PUTALL come from the CamelInfinispanKey, CamelInfinispanValue and CamelInfinispanMap headers, or the key and value options.

Producer output

unknown

The result of the operation, which the CamelInfinispanOperation header can set: the value for GET, the previous value for PUT, the default, which is null unless the FORCE_RETURN_VALUE flag is set, a Boolean for CONTAINSKEY, an Integer for SIZE, a List for QUERY and a CompletableFuture for the ASYNC operations; PUTALL and CLEAR keep the body. With resultHeader the result goes to that header and the body is kept.

  • With operation=PUTASYNC: pojo (java.util.concurrent.CompletableFuture)

  • With operation=PUTALL: unchanged

  • With operation=PUTALLASYNC: pojo (java.util.concurrent.CompletableFuture)

  • With operation=PUTIFABSENTASYNC: pojo (java.util.concurrent.CompletableFuture)

  • With operation=CONTAINSKEY: value (java.lang.Boolean)

  • With operation=CONTAINSVALUE: value (java.lang.Boolean)

  • With operation=REMOVEASYNC: pojo (java.util.concurrent.CompletableFuture)

  • With operation=REPLACEASYNC: pojo (java.util.concurrent.CompletableFuture)

  • With operation=SIZE: value (java.lang.Integer)

  • With operation=CLEAR: unchanged

  • With operation=CLEARASYNC: pojo (java.util.concurrent.CompletableFuture)

  • With operation=QUERY: list or unchanged

  • With operation=STATS: pojo (org.infinispan.client.hotrod.ServerStatistics)

  • With operation=COMPUTEASYNC: pojo (java.util.concurrent.CompletableFuture)

Not known when resultHeader is set.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Camel Operations

This section lists all available operations, along with their header information.

Table 1. Put Operations
Operation Name Description

InfinispanOperation.PUT

Put a key/value pair in the cache, optionally with expiration

InfinispanOperation.PUTASYNC

Asynchronously puts a key/value pair in the cache, optionally with expiration

InfinispanOperation.PUTIFABSENT

Put a key/value pair in the cache if it did not exist, optionally with expiration

InfinispanOperation.PUTIFABSENTASYNC

Asynchronously puts a key/value pair in the cache if it did not exist, optionally with expiration

  • Required Headers:

    • CamelInfinispanKey

    • CamelInfinispanValue

  • Optional Headers:

    • CamelInfinispanLifespanTime

    • CamelInfinispanTimeUnit

    • CamelInfinispanMaxIdleTime

    • CamelInfinispanMaxIdleTimeUnit

  • Result:

    • the message body, or the header named by the resultHeader option

Table 2. Put All Operations
Operation Name Description

InfinispanOperation.PUTALL

Adds multiple entries to a cache, optionally with expiration

CamelInfinispanOperation.PUTALLASYNC

Asynchronously adds multiple entries to a cache, optionally with expiration

  • Required Headers:

    • CamelInfinispanMap

  • Optional Headers:

    • CamelInfinispanLifespanTime

    • CamelInfinispanTimeUnit

    • CamelInfinispanMaxIdleTime

    • CamelInfinispanMaxIdleTimeUnit

Table 3. Get Operations
Operation Name Description

InfinispanOperation.GET

Retrieve the value associated with a specific key from the cache

InfinispanOperation.GETORDEFAULT

Retrieves the value, or default value, associated with a specific key from the cache

  • Required Headers:

    • CamelInfinispanKey The resulting value is returned in the exchange body.

Table 4. Contains Key Operation
Operation Name Description

InfinispanOperation.CONTAINSKEY

Determines whether a cache contains a specific key

  • Required Headers

    • CamelInfinispanKey

  • Result:

    • the message body, or the header named by the resultHeader option

Table 5. Contains Value Operation
Operation Name Description

InfinispanOperation.CONTAINSVALUE

Determines whether a cache contains a specific value

  • Required Headers:

    • CamelInfinispanValue

  • Result:

    • the message body, or the header named by the resultHeader option

Table 6. Remove Operations
Operation Name Description

InfinispanOperation.REMOVE

Removes an entry from a cache, optionally only if the value matches a given one

InfinispanOperation.REMOVEASYNC

Asynchronously removes an entry from a cache, optionally only if the value matches a given one

  • Required Headers:

    • CamelInfinispanValue

  • Optional Headers:

    • CamelInfinispanValue

  • Result:

    • the message body, or the header named by the resultHeader option

Table 7. Replace Operations
Operation Name Description

InfinispanOperation.REPLACE

Conditionally replaces an entry in the cache, optionally with expiration

InfinispanOperation.REPLACEASYNC

Asynchronously conditionally replaces an entry in the cache, optionally with expiration

  • Required Headers:

    • CamelInfinispanKey

    • CamelInfinispanValue

    • CamelInfinispanOldValue

  • Optional Headers:

    • CamelInfinispanLifespanTime

    • CamelInfinispanTimeUnit

    • CamelInfinispanMaxIdleTime

    • CamelInfinispanMaxIdleTimeUnit

  • Result:

    • the message body, or the header named by the resultHeader option

Table 8. Clear Operations
Operation Name Description

InfinispanOperation.CLEAR

Clears the cache

InfinispanOperation.CLEARASYNC

Asynchronously clears the cache

Table 9. Size Operation
Operation Name Description

InfinispanOperation.SIZE

Returns the number of entries in the cache

  • Result:

    • the message body, or the header named by the resultHeader option

Table 10. Stats Operation
Operation Name Description

InfinispanOperation.STATS

Returns statistics about the cache

  • Result:

    • the message body, or the header named by the resultHeader option

Table 11. Query Operation
Operation Name Description

InfinispanOperation.QUERY

Executes a query on the cache

  • Required Headers:

    • CamelInfinispanQueryBuilder The resulting value is returned in the exchange body.

Write methods like put(key, value) and remove(key) do not return the previous value by default.

Key and cache name headers

The key option of the endpoint takes precedence over the CamelInfinispanKey header. When the endpoint does not set key, the producer uses the CamelInfinispanKey header.

The CamelInfinispanCacheName header takes precedence over the cache name of the endpoint.

An infinispan consumer sets CamelInfinispanKey and CamelInfinispanCacheName to the key and the cache of the event. When a route sends those events to an infinispan producer, the producer works on the cache of the event, and on the key of the event unless the endpoint sets key. To use the cache and the key configured on the producer endpoint, remove the headers first:

from("infinispan:source")
    .removeHeaders("CamelInfinispan*")
    .to("infinispan:target?operation=PUT&key=myKey&value=myValue");

Examples

  • Put a key/value into a named cache:

    • Java

    • XML

    • YAML

    from("direct:start")
        .setHeader("CamelInfinispanOperation").constant("PUT") (1)
        .setHeader("CamelInfinispanKey").constant("123") (2)
        .setHeader("CamelInfinispanValue").constant("Hello") (3)
        .to("infinispan:myCacheName?cacheContainer=#cacheContainer"); (4)
    1 Set the operation to perform
    2 Set the key used to identify the element in the cache
    3 Set the value to store: the message body is not used
    4 Use the configured cache manager cacheContainer from the registry to put an element to the cache named myCacheName
    <route>
      <from uri="direct:start"/>
      <setHeader name="CamelInfinispanOperation">
        <constant>PUT</constant>
      </setHeader>
      <setHeader name="CamelInfinispanKey">
        <constant>123</constant>
      </setHeader>
      <setHeader name="CamelInfinispanValue">
        <constant>Hello</constant>
      </setHeader>
      <to uri="infinispan:myCacheName?cacheContainer=#cacheContainer"/>
    </route>
    - route:
        from:
          uri: direct:start
          steps:
            - setHeader:
                name: CamelInfinispanOperation
                constant: PUT
            - setHeader:
                name: CamelInfinispanKey
                constant: "123"
            - setHeader:
                name: CamelInfinispanValue
                constant: Hello
            - to:
                uri: infinispan:myCacheName
                parameters:
                  cacheContainer: "#cacheContainer"

    It is possible to configure the lifetime and/or the idle time before the entry expires and gets evicted from the cache, as example:

    • Java

    • XML

    • YAML

    from("direct:start")
        .setHeader("CamelInfinispanOperation").constant("GET")
        .setHeader("CamelInfinispanKey").constant("123")
        .setHeader("CamelInfinispanLifespanTime").constant(100L) (1)
        .setHeader("CamelInfinispanTimeUnit").constant("MILLISECONDS") (2)
        .to("infinispan:myCacheName");
    1 Set the lifespan of the entry
    2 Set the time unit for the lifespan
    <route>
      <from uri="direct:start"/>
      <setHeader name="CamelInfinispanOperation">
        <constant>GET</constant>
      </setHeader>
      <setHeader name="CamelInfinispanKey">
        <constant>123</constant>
      </setHeader>
      <setHeader name="CamelInfinispanLifespanTime">
        <constant resultType="java.lang.Long">100</constant>
      </setHeader>
      <setHeader name="CamelInfinispanTimeUnit">
        <constant>MILLISECONDS</constant>
      </setHeader>
      <to uri="infinispan:myCacheName"/>
    </route>
    - route:
        from:
          uri: direct:start
          steps:
            - setHeader:
                name: CamelInfinispanOperation
                constant: GET
            - setHeader:
                name: CamelInfinispanKey
                constant: "123"
            - setHeader:
                name: CamelInfinispanLifespanTime
                constant: "100"
            - setHeader:
                name: CamelInfinispanTimeUnit
                constant: MILLISECONDS
            - to:
                uri: infinispan:myCacheName
  • Queries

Java-only: requires InfinispanQueryBuilder implementation
from("direct:start")
    .setHeader("CamelInfinispanOperation").constant("QUERY")
    .setHeader("CamelInfinispanQueryBuilder").constant(
        InfinispanQueryBuilder.create("FROM org.example.User u WHERE u.name LIKE '%abc%'"))
    .to("infinispan:myCacheName?cacheContainer=#cacheManager");

+

The .proto descriptors for domain objects must be registered with the remote Data Grid server, see Remote Query Example in the official Infinispan documentation.

  • Custom Listeners

    • Java

    • XML

    • YAML

    from("infinispan://?cacheContainer=#cacheManager&customListener=#myCustomListener")
        .to("mock:result");
    <route>
      <from uri="infinispan://?cacheContainer=#cacheManager&amp;customListener=#myCustomListener"/>
      <to uri="mock:result"/>
    </route>
    - route:
        from:
          uri: "infinispan://"
          parameters:
            cacheContainer: "#cacheManager"
            customListener: "#myCustomListener"
          steps:
            - to:
                uri: mock:result

    The instance of myCustomListener must exist and Camel should be able to look it up from the Registry. Users are encouraged to extend the org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener class and annotate the resulting class with @ClientListener which can be found in the package org.infinispan.client.hotrod.annotation.

Using the Infinispan based idempotent repository

In this section, we will use the Infinispan based idempotent repository.

  • Java

  • XML

InfinispanRemoteConfiguration conf = new InfinispanRemoteConfiguration(); (1)
conf.setHosts("localhost:11222");

InfinispanRemoteIdempotentRepository repo = new InfinispanRemoteIdempotentRepository("idempotent");  (2)
repo.setConfiguration(conf);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("direct:start")
            .idempotentConsumer(header("MessageID"), repo) (3)
            .to("mock:result");
    }
});
  1. Configure the cache

  2. Configure the repository bean

  3. Set the repository to the route

<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.remote.InfinispanRemoteIdempotentRepository" destroy-method="stop">
  <constructor-arg value="idempotent"/> (1)
  <property name="configuration"> (2)
    <bean class="org.apache.camel.component.infinispan.remote.InfinispanRemoteConfiguration">
      <property name="hosts" value="localhost:11222"/>
    </bean>
  </property>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start" />
        <idempotentConsumer idempotentRepository="infinispanRepo"> (3)
            <header>MessageID</header>
            <to uri="mock:result" />
        </idempotentConsumer>
    </route>
</camelContext>
  1. Set the name of the cache that will be used by the repository

  2. Configure the repository bean

  3. Set the repository to the route

Using the Infinispan based aggregation repository

In this section, we will use the Infinispan based aggregation repository.

  • Java

  • XML

InfinispanRemoteConfiguration conf = new InfinispanRemoteConfiguration(); (1)
conf.setHosts("localhost:11222");

InfinispanRemoteAggregationRepository repo = new InfinispanRemoteAggregationRepository();  (2)
repo.setCacheName("aggregation");
repo.setConfiguration(conf);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("direct:start")
                .aggregate(header("MessageID"))
                .completionSize(3)
                .aggregationRepository(repo) (3)
                .aggregationStrategy("myStrategy")
                .to("mock:result");
    }
});
  1. Configure the cache

  2. Create the repository bean

  3. Set the repository to the route

<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.remote.InfinispanRemoteAggregationRepository" destroy-method="stop">
  <constructor-arg value="aggregation"/> (1)
  <property name="configuration"> (2)
    <bean class="org.apache.camel.component.infinispan.remote.InfinispanRemoteConfiguration">
      <property name="hosts" value="localhost:11222"/>
    </bean>
  </property>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start" />
        <aggregate aggregationStrategy="myStrategy"
                   completionSize="3"
                   aggregationRepository="infinispanRepo"> (3)
            <correlationExpression>
                <header>MessageID</header>
            </correlationExpression>
            <to uri="mock:result"/>
        </aggregate>
    </route>
</camelContext>
  1. Set the name of the cache that will be used by the repository

  2. Configure the repository bean

  3. Set the repository to the route

Embedding store support with camel-langchain4j-embeddings

This component provides the capability to store and query vector embeddings. To activate this functionality, add camel-langchain4j-embeddings to your project.

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-langchain4j-embeddings</artifactId>
    <!-- use the same version as your Camel core version -->
    <version>x.x.x</version>
</dependency>

If you want to disable this functionality, set the embeddingStoreEnabled option to false.

To store an embedding:

Java-only: requires DataType constructor for embedding transformation
from("direct:put")
    .to("langchain4j-embeddings:create")
    .setHeader("CamelInfinispanOperation").constant("PUT")
    .transformDataType(new DataType("infinispan:embeddings"))
    .to("infinispan:myCache?embeddingStoreDimension=384");

The embeddingStoreDimension option must be specified. It must also match the dimension of the embedding model used by the langchain4j-embeddings endpoint.

To query embeddings:

Java-only: requires DataType constructor for embedding transformation
from("direct:query")
    .to("langchain4j-embeddings:create")
    .setHeader("CamelInfinispanOperation").constant("QUERY")
    .transformDataType(new DataType("infinispan:embeddings"))
    .to("infinispan:myCache?embeddingStoreDimension=384");

By default, a simple vector kNN search query is executed that looks like the following.

select i, score(i) from CamelInfinispanRemoteEmbedding384 i
where i.embedding <-> [the vector embedding]~3

The ~3 part is the k of the kNN search: the number of nearest embeddings that the query returns. It is set with the embeddingStoreDistance option. The similarity function that compares the embeddings is set with the embeddingStoreVectorSimilarity option.

The result of the query operation is List<Object[]>. The elements of the Object array are as follows.

Index Type Description

0

InfinispanRemoteEmbedding

Information about the embedding such as the embedding text and its float array representation.

1

Float

The score in relation to how closely the embedding matches the search text.

With the release of Infinispan 11, it is required to set the encoding configuration on any cache created. This is critical for consuming events too. For more information, have a look at Data Encoding and MediaTypes in the official Infinispan documentation.