Nats
Send and receive messages with the NATS messaging system, including JetStream streams.
What’s inside
-
Nats component, URI syntax:
nats:topic
Please refer to the above links for usage and configuration details.
Maven coordinates
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-nats-starter</artifactId>
</dependency> Spring Boot Auto-Configuration
The starter supports 46 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
camel.component.nats.ack-policy | The acknowledgement policy of the JetStream consumer. None: the server does not wait for an acknowledgement, so a message that failed in Camel is not delivered again. All: the acknowledgement of a message also acknowledges all the messages before it. Explicit: each message is acknowledged on its own, after Camel processed it, and a message that failed is negatively acknowledged (nak), so the server delivers it again. Not used when consumerConfiguration is set. | explicit | AckPolicy |
camel.component.nats.ack-wait | The time in milliseconds that the server waits for the acknowledgement of a JetStream message before it delivers the message again. 0 or less uses the server default (30 seconds). Not used when consumerConfiguration is set. | 30000 | Long |
camel.component.nats.autowired-enabled | 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 |
camel.component.nats.bridge-error-handler | 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 |
camel.component.nats.configuration | To use a shared configuration. The option is a org.apache.camel.component.nats.NatsConfiguration type. | NatsConfiguration | |
camel.component.nats.connection | An existing NATS Connection to use, instead of the connection that Camel creates from the servers and the connection options. Camel does not close it. The option is a io.nats.client.Connection type. | Connection | |
camel.component.nats.connection-timeout | The time in milliseconds to wait for a connection to a server to be established. | 2000 | Integer |
camel.component.nats.consumer-configuration | A JetStream ConsumerConfiguration to use for the consumer, for settings that have no option of their own. When set, it is used as it is, and the options ackPolicy, ackWait, maxDeliver and durableName are not used. The option is a io.nats.client.api.ConsumerConfiguration type. | ConsumerConfiguration | |
camel.component.nats.credentials-file-path | The path of a NATS credentials file, used to authenticate with the server. It is loaded from the classpath by default; prefix it with classpath:, file: or http: to load it from elsewhere. | String | |
camel.component.nats.durable-name | The name of the durable JetStream consumer, which keeps its position in the stream when Camel stops. The consumer on the server is named after this value followed by -durable (orders becomes orders-durable). Without it, the consumer is ephemeral. It cannot contain whitespace, '.', '*', '>', path separators (forward or backward slash) or non-printable characters. Not used when consumerConfiguration is set. | String | |
camel.component.nats.enabled | Whether to enable auto configuration of the nats component. This is enabled by default. | Boolean | |
camel.component.nats.flush-connection | Whether to flush the connection, waiting until the server has received what was sent, when the consumer or the producer stops. | true | Boolean |
camel.component.nats.flush-timeout | The time in milliseconds to wait for the flush of the connection when stopping. | 1000 | Integer |
camel.component.nats.header-filter-strategy | To use a custom HeaderFilterStrategy to filter the headers that are sent to and received from NATS. The option is a org.apache.camel.spi.HeaderFilterStrategy type. | HeaderFilterStrategy | |
camel.component.nats.hostname-verification | Whether to check that the certificate of the NATS server matches the host Camel connects to, when TLS is used. The client then keeps the host name of a server for TLS, and connects to the fastest of its IP addresses. A server that is given, or that the cluster announces, by its IP address needs a certificate that names that address. When disabled, any certificate trusted by the JVM, or by the sslContextParameters, is accepted, whatever host it was issued for. | true | Boolean |
camel.component.nats.jetstream-async | Whether the producer publishes to JetStream with the asynchronous publish of the NATS client, waiting up to requestTimeout for the acknowledgement, or with the synchronous one. Either way, the exchange completes once the stream acknowledged the message. | true | Boolean |
camel.component.nats.jetstream-enabled | Whether to use JetStream: the producer publishes to a stream and waits for its acknowledgement, and the consumer reads from the stream named by jetstreamName. When the server does not have JetStream, the endpoint uses core NATS. | false | Boolean |
camel.component.nats.jetstream-name | The name of the JetStream stream. The consumer reads from this stream (it is required for a JetStream consumer). When the stream does not exist, the consumer creates it with the subject of the topic. The producer creates it in the same way, unless another stream already takes in the subject. The producer publishes to the subject, and the message is stored by the stream that takes in the subject, whatever its name. | String | |
camel.component.nats.lazy-start-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 |
camel.component.nats.manual-ack | Whether the route acknowledges the JetStream messages itself, with the NatsManualAck that the consumer puts in the CamelNatsManualAck header (ack, nak and term). The consumer then does not acknowledge a message when its exchange completes: a message that is not acknowledged is delivered again after ackWait. Only used with jetstreamEnabled=true, and has no effect with ackPolicy=None. | false | Boolean |
camel.component.nats.max-deliver | The maximum number of times the server delivers a JetStream message to the consumer. After that, the server no longer delivers the message, which stays in the stream. 0 (the default) keeps the server default, which is no limit. Set it so that a message that always fails is not delivered forever. Not used when consumerConfiguration is set. | Long | |
camel.component.nats.max-messages | The number of messages after which the consumer unsubscribes from the topic, and receives no more messages. Not used with JetStream. | String | |
camel.component.nats.max-pings-out | The maximum number of pings without a response from the server. When it is reached, the client considers the connection stale. | 2 | Integer |
camel.component.nats.max-reconnect-attempts | The maximum number of reconnect attempts to each server, when reconnect is enabled. -1 means no limit, and 0 means no reconnect. | 60 | Integer |
camel.component.nats.nack-wait | The delay in milliseconds before the server delivers a JetStream message again, after the consumer negatively acknowledged (nak) it because its exchange failed. 0 or less delivers it again at once, which can make the consumer process the same message over and over again while an error lasts. | 5000 | Long |
camel.component.nats.no-echo | Whether to ask the server not to send back to this connection the messages it publishes, when the connection also subscribes to their subject. | false | Boolean |
camel.component.nats.no-randomize-servers | Whether to connect to the servers in the order they are given, instead of in a random order. | false | Boolean |
camel.component.nats.pedantic | Whether to ask the server for pedantic mode, in which it does extra checks on what the client sends. This affects performance. | false | Boolean |
camel.component.nats.ping-interval | The interval in milliseconds at which the client sends a ping to the server, to check that the connection is still alive. | 120000 | Integer |
camel.component.nats.pool-size | The size of the thread pool of the consumer. The pool runs the subscribe and, with a JetStream pull subscription, the fetch loop. The messages are processed one at a time, on the thread of the NATS dispatcher or of the fetch loop, so a larger pool does not process them in parallel. | 10 | Integer |
camel.component.nats.pull-batch-size | The maximum number of messages to fetch per pull request. Only used with a JetStream pull subscription. | 10 | Integer |
camel.component.nats.pull-fetch-timeout | The maximum time in milliseconds that a fetch waits for messages. Only used with a JetStream pull subscription. | 1000 | Long |
camel.component.nats.pull-subscription | Whether the JetStream consumer uses a pull subscription, in which it fetches the messages in batches, or a push subscription, in which the server delivers them. | true | Boolean |
camel.component.nats.queue-name | The name of the queue group to subscribe with. The server delivers each message to only one of the subscribers of the group. With JetStream, it is the deliver group of a push subscription; a pull subscription does not use it. | String | |
camel.component.nats.reconnect | Whether the NATS client reconnects when the connection to the server is lost. When disabled, the connection is closed instead. | true | Boolean |
camel.component.nats.reconnect-time-wait | The time in milliseconds to wait between two reconnect attempts to the same server. | 2000 | Integer |
camel.component.nats.reply-subject | The reply subject to set on the messages that the producer publishes without waiting for a reply (exchangePattern=InOnly), so that the subscribers can send their responses there. Not used for request-reply (InOut), where the NATS client uses its own reply subject. | String | |
camel.component.nats.reply-to-disabled | Whether the consumer does not send a reply to a message that has a reply subject, even with exchangePattern=InOut. | false | Boolean |
camel.component.nats.request-cleanup-interval | The interval in milliseconds at which the NATS client removes the requests that were cancelled or timed out. The client gives up on a request without a timeout of its own, such as a request-reply message of the producer or an asynchronous JetStream publish, after this interval (to twice that). | 5000 | Integer |
camel.component.nats.request-timeout | The time in milliseconds that the producer waits for the reply of a request-reply message (exchangePattern=InOut) and, with JetStream, for the acknowledgement of a published message. The NATS client also gives up on a reply, and with jetstreamAsync=true on the acknowledgement, after requestCleanupInterval (to twice that), so a longer wait needs a longer requestCleanupInterval too. | 20000 | Long |
camel.component.nats.secure | Whether TLS is required for the connection. | false | Boolean |
camel.component.nats.servers | The URLs of one or more NATS servers, separated by comma. A URL without a scheme, such as localhost:4222, gets nats:// in front of it. Not used when a connection is given. | String | |
camel.component.nats.ssl-context-parameters | To configure security using SSLContextParameters. The option is a org.apache.camel.support.jsse.SSLContextParameters type. | SSLContextParameters | |
camel.component.nats.trace-connection | Whether the NATS client prints connection trace messages to standard out, for debugging connection issues. | false | Boolean |
camel.component.nats.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
camel.component.nats.verbose | Whether to ask the server for verbose mode, in which it confirms each protocol message with +OK. | false | Boolean |