Infinispan Sink
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Stores the body of each message under a key in a cache of a remote Infinispan server, or in Red Hat Data Grid, or removes the entry of the key.
Use it to share data between applications through an Infinispan cache, for example the latest status of each order or a lookup table that other services read, or to keep an entry only for a while, such as a session. To react to the changes in a cache, use infinispan-source.
Input: the body is the value to store, as text. The key header (or ce-key) is the key; without one, a new unique id is used as the key, so each message adds a new entry. What is done depends on operation. By default (PUT), a value that is already under the key is replaced. PUTIFABSENT keeps a value that is already there, and REPLACE stores the body only under a key that has a value. REMOVE deletes the entry of the key: with an empty body always, and with a body only when the value stored is equal to the body.
Output: when it is used inside a route, the message has no body afterwards. With REMOVE and a body, the body afterwards is true when the entry was deleted and false when it was not.
Good to know: the cache must already exist on the server. A body that the Infinispan client cannot store, such as a Map, fails the message; turn it into JSON text first, for example with json-serialize-action. With lifespan or maxIdle, the entries are removed after that time. Recent Infinispan servers do not accept the default saslMechanism of DIGEST-MD5: set it to SCRAM-SHA-512. The connection has TLS only when sslTruststoreLocation is set, together with sslSniHostName. Headers that start with CamelInfinispan are removed from the message first, so they cannot change what the Kamelet does.
Configuration Options
The following table summarizes the configuration options available for the infinispan-sink Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Cache Name | Required The name of the cache to store the values in. It must exist on the server. | string | orders | ||
Hosts | Required The address of the Infinispan server, as | string | infinispan.example.com:11222 | ||
Password | Required The password of the Infinispan user in | string | |||
Username | Required The Infinispan user to log in as. | string | |||
Lifespan | How long an entry stays in the cache after it is stored, in the unit of | integer | 60 | ||
Lifespan Time Unit | The unit of Enum values: * MILLISECONDS * SECONDS * MINUTES * HOURS * DAYS | string | SECONDS | ||
Max Idle Time | How long an entry stays in the cache when it is not read or written, in the unit of | integer | 300 | ||
Max Idle Time Unit | The unit of Enum values: * MILLISECONDS * SECONDS * MINUTES * HOURS * DAYS | string | SECONDS | ||
Operation | What to do with each message. Enum values: * PUT * PUTIFABSENT * REPLACE * REMOVE | string | REMOVE | ||
SASL Mechanism | How the user and password are checked by the server. Recent Infinispan servers accept | string | DIGEST-MD5 | SCRAM-SHA-512 | |
Secure | If true, it logs in with | boolean | true | ||
Security Realm | The security realm of the server that holds the user. Keep the default unless your Infinispan administrator set up another realm. | string | default | ||
Security Server Name | The name of the server, used when logging in. Keep the default unless your Infinispan administrator changed it. | string | infinispan | ||
TLS Server Name | The host name of the server as its certificate names it, such as | string | infinispan.example.com | ||
Trust Store Location | The path of a file with the certificate of the server, or of the authority that signed it, to connect with TLS. It is a trust store in PKCS12 or JKS format, which needs | string | /etc/infinispan/truststore.p12 | ||
Trust Store Password | The password of the trust store file in | string |
Dependencies
At runtime, the infinispan-sink Kamelet relies upon the presence of the following dependencies:
-
camel:kamelet
-
camel:infinispan
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:infinispan-sink" You can now run it directly through the following command
camel run route.yaml Infinispan Sink Kamelet Description
Authentication
This Kamelet uses username and password authentication to connect to Infinispan cache instances.
Security Configuration
-
Authentication: Enabled by default (secure: true). It is a login with username and password, not TLS.
-
TLS: Off by default. It is on when sslTruststoreLocation is set, and sslSniHostName is then required. See Example with TLS and Expiration.
-
SASL Mechanism: DIGEST-MD5 (default). Recent Infinispan servers do not accept it: set
saslMechanismtoSCRAM-SHA-512. -
Security Realm: "default" realm
-
Security Server Name: "infinispan" (default)
Required Configuration
-
Cache Name: The name of the Infinispan cache to use
-
Hosts: Host address of the Infinispan instance
-
Username and Password: Credentials for authentication
Cache Operations
The body of each message is stored as the value in the specified cache, which must already exist on the server. The key comes from a header, or is a new unique id.
The operation option sets what is done with each message:
| Operation | What it does |
|---|---|
| Stores the body under the key, and replaces a value that is already there. |
| Stores the body only when the key has no value yet. |
| Stores the body only when the key already has a value. |
| Deletes the entry of the key. With an empty body, it is always deleted. With a body, it is deleted only when the value stored is equal to the body, and the body afterwards is |
Expiration
With lifespan, an entry is removed that long after it is stored. With maxIdle, an entry is removed when it has not been read or written for that long. Both are in seconds unless lifespanTimeUnit or maxIdleTimeUnit says otherwise, and they can be used together. They apply to PUT, PUTIFABSENT and REPLACE.
Example with TLS and Expiration
The Infinispan client checks the certificate of the server against the file in sslTruststoreLocation only: it does not use the certificates that Java trusts by default. The file is a PKCS12 or JKS trust store with its password, or a PEM file such as the ca.crt of the server, without a password. sslSniHostName is the host name the certificate of the server is for.
- route:
from:
uri: "kafka:sessions"
steps:
- setHeader:
name: key
simple: "$\{header.kafka.KEY}"
- to:
uri: "kamelet:infinispan-sink"
parameters:
cacheName: "sessions"
hosts: "infinispan.example.com:11222"
username: "camel"
password: "secret"
saslMechanism: "SCRAM-SHA-512"
sslTruststoreLocation: "/etc/infinispan/ca.crt"
sslSniHostName: "infinispan.example.com"
lifespan: 30
lifespanTimeUnit: "MINUTES" Each record is stored under its Kafka key, over TLS, and removed from the cache 30 minutes later.
To delete entries instead, set operation: "REMOVE" and send messages with an empty body and the key header.