Ignite Cache
Since Camel 2.17
Both producer and consumer are supported
The Ignite Cache endpoint is one of camel-ignite endpoints that allow you to interact with an Ignite Cache. This offers both a Producer (to invoke cache operations on an Ignite cache) and a Consumer (to consume changes from a continuous query).
The cache value is the body of the message, and the cache key is in the CamelIgniteCacheKey message header. GET and REMOVE take the key from the body when that header is not set. A PUT of a Map body without that header puts all its entries; with the header, or with treatCollectionsAsCacheObjects=true, the Map is stored as one value.
Even if you configure a fixed operation in the endpoint URI, you can vary it per-exchange by setting the CamelIgniteCacheOperation message header. Without either, the producer fails.
With fireExistingQueryResults=true, the consumer first sends the entries that the initial query finds, each with the value as the body and the key in the CamelIgniteCacheKey header, like the events that follow.
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,*.yamlfiles, 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 Ignite Cache component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
A Spring XML configuration of Ignite to start a new Ignite node with (Ignition.start): a URL, an InputStream, or a String with the path or URL of the file. It takes precedence over igniteConfiguration, and is ignored when ignite is set. The component stops the node when it stops. | Object | ||
An existing Ignite instance to use, instead of starting a new Ignite node. The component neither starts nor stops it, and ignores configurationResource and igniteConfiguration. | Ignite | ||
An IgniteConfiguration to start a new Ignite node with (Ignition.start), used when neither ignite nor configurationResource is set. The component stops the node when it stops. | IgniteConfiguration | ||
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 | |
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 | |
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 |
Endpoint Options
The Ignite Cache endpoint is configured using URI syntax:
ignite-cache:cacheName
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether the producer keeps the incoming message body when the Ignite operation has no result, such as a cache PUT, REMOVE or CLEAR, a queue PUT or CLEAR, a set CLEAR, a compute RUN or AFFINITY_RUN, or a messaging send. When false, the body is null after such an operation. Not used by ignite-idgen and ignite-events. | true | boolean | |
Whether a Collection in the body is one object, instead of several elements. By default a cache PUT of a Map without the CamelIgniteCacheKey header puts each of its entries, a cache GET or REMOVE of a Set works on each of its keys, a queue or set ADD, CONTAINS or REMOVE works on each element, and an UNORDERED messaging send sends each element as a message. When true, the Collection is stored, looked up or sent as one object. Not used by ignite-compute, ignite-idgen and ignite-events. | false | boolean | |
Whether Ignite removes the remote filter of the continuous query from the other nodes when this node, which started the query, leaves the cluster. When false, the filter is removed only when the consumer stops and closes the query. Default value notice: ContinuousQuery.DFLT_AUTO_UNSUBSCRIBE. | true | boolean | |
Whether the continuous query consumer, when it starts, first sends the entries that the query option finds, each as an exchange with the value as the body and the key in the CamelIgniteCacheKey header. Without the query option, it sends nothing. | false | boolean | |
Whether the continuous query consumer sends each cache entry event as its own exchange, with the new value as the body and the key, old value and event type in headers. When false, each batch of events that Ignite delivers is one exchange, with the CacheEntryEvents of the batch as the body. | true | boolean | |
The number of cache entry events that each node buffers before it sends them to the continuous query consumer (ContinuousQuery.setPageSize). 1 sends each event at once; a larger size sends the events in batches, when the buffer is full or after timeInterval. Must be above 0. Default value notice: ContinuousQuery.DFLT_PAGE_SIZE. | 1 | int | |
The initial query of the continuous query consumer (ContinuousQuery.setInitialQuery), such as a ScanQuery. It selects the existing entries that fireExistingQueryResults=true sends to the route; the changes are received whatever this query is. The QUERY operation of the producer does not use it: it takes the query from the CamelIgniteCacheQuery header or the body. | Query | ||
A CacheEntryEventSerializableFilter that Ignite runs on the nodes that hold the cache data, to select the cache entry events sent to the continuous query consumer. By default all events are sent. | CacheEntryEventSerializableFilter | ||
The time in milliseconds after which each node sends its buffered cache entry events to the continuous query consumer even when the buffer of pageSize events is not full (ContinuousQuery.setTimeInterval). 0 sends them only when the buffer is full. Only matters with a pageSize above 1; must not be negative. Default value notice: ContinuousQuery.DFLT_TIME_INTERVAL. | 0 | long | |
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 | |
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 | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
The CachePeekMode that selects the entries the SIZE operation counts, such as PRIMARY, BACKUP or NEAR. The CamelIgniteCachePeekMode header overrides it. Enum values:
| ALL | CachePeekMode | |
Whether to fail when the cache does not exist, instead of creating it (Ignite.createCache). It is checked when the producer is created, and when the continuous query consumer starts. | false | boolean | |
The cache operation to invoke. The CamelIgniteCacheOperation header overrides it; with neither, the producer fails. Enum values:
| IgniteCacheOperation | ||
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 |
Message Headers
The Ignite Cache component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The key of the cache entry. PUT and REPLACE store the body under this key; GET and REMOVE use it as the key, or else the body (a Set as several keys). The consumer sets it to the key of the entry that changed. | Object | |
CamelIgniteCacheQuery (producer) Constant: | The Ignite Query, such as a ScanQuery, that the QUERY operation runs. Without this header, the body must be the query. | Query | |
CamelIgniteCacheOperation (producer) Constant: | The cache operation to invoke, overriding the operation option. Enum values:
| IgniteCacheOperation | |
CamelIgniteCachePeekMode (producer) Constant: | The CachePeekMode, or a Collection of them, that selects the entries the SIZE operation counts, overriding the cachePeekMode option. Enum values:
| CachePeekMode | |
CamelIgniteCacheEventType (consumer) Constant: | The type of the cache entry event the continuous query consumer received: CREATED, UPDATED, REMOVED or EXPIRED. Set only with oneExchangePerUpdate=true. Enum values:
| EventType | |
CamelIgniteCacheName (consumer) Constant: | The name of the cache the consumer received the entry from. The producer does not read it: to choose the cache per message, use a dynamic endpoint such as toD or the Recipient List EIP. | String | |
CamelIgniteCacheOldValue (common) Constant: | With this header, REPLACE replaces the value only when the current value of the key equals this one; without it, REPLACE replaces the value when the key exists. The consumer sets it to the value the entry had before the change (with oneExchangePerUpdate=true). | Object |
Message Body
The message body at each side of the Ignite Cache 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 |
| The new value of the cache entry that changed, with its key in the CamelIgniteCacheKey header, the old value in CamelIgniteCacheOldValue and the event type in CamelIgniteCacheEventType. With oneExchangePerUpdate=false a List of the CacheEntryEvents of Ignite per batch; with fireExistingQueryResults=true the entries the initial query finds come first, each with its value as the body and its key in the CamelIgniteCacheKey header.
|
Producer input |
| PUT and REPLACE store the body as the value of the key in the CamelIgniteCacheKey header, a Map as well. A PUT of a Map without that header puts all its entries, unless treatCollectionsAsCacheObjects=true; no body fails. GET and REMOVE take the key from that header, or else from the body, where a Set is several keys. QUERY needs an Ignite Query in the body or the CamelIgniteCacheQuery header. SIZE, CLEAR and REBALANCE do not use the body. The operation is the operation option or the CamelIgniteCacheOperation header; with neither the producer fails. |
Producer output |
| GET gives the cached value, or null when the key is not cached, and a Map of the keys and their values for a Set of keys. QUERY gives an Iterator of the entries found, closed when the exchange completes. SIZE gives the number of entries. The others leave the body.
Not known when |
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
The component needs an Ignite node: Ignite describes the ways to give it one. A node of its own with the default configuration takes one line in application.properties. On Java 17 and later, Ignite also needs the --add-opens JVM options that its documentation lists.
camel.component.ignite-cache.ignite-configuration = #class:org.apache.ignite.configuration.IgniteConfiguration The following routes put an order in the orders cache, and get it back by its key:
- route:
from:
uri: direct:putOrder
steps:
- setHeader:
name: CamelIgniteCacheKey
expression:
simple:
expression: "${header.orderId}"
- to:
uri: ignite-cache:orders
parameters:
operation: PUT
- route:
from:
uri: direct:getOrder
steps:
- setHeader:
name: CamelIgniteCacheKey
expression:
simple:
expression: "${header.orderId}"
- to:
uri: ignite-cache:orders
parameters:
operation: GET