Chapter 227. Nats Component

Available as of Camel version 2.17

NATS is a fast and reliable messaging platform.

Maven users will need to add the following dependency to their pom.xml for this component.

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

227.1. URI format

nats:servers[?options]

Where servers represents the list of NATS servers.

227.2. Options

The Nats component supports 2 options which are listed below.

NameDescriptionDefaultType

useGlobalSslContext Parameters (security)

Enable usage of global SSL context parameters.

false

boolean

resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

boolean

The Nats endpoint is configured using URI syntax:

nats:servers

with the following path and query parameters:

227.2.1. Path Parameters (1 parameters):

NameDescriptionDefaultType

servers

Required URLs to one or more NAT servers. Use comma to separate URLs when specifying multiple servers.

 

String

227.2.2. Query Parameters (22 parameters):

NameDescriptionDefaultType

flushConnection (common)

Define if we want to flush connection or not

false

boolean

flushTimeout (common)

Set the flush timeout

1000

int

maxReconnectAttempts (common)

Max reconnection attempts

3

int

noRandomizeServers (common)

Whether or not randomizing the order of servers for the connection attempts

false

boolean

pedantic (common)

Whether or not running in pedantic mode (this affects performace)

false

boolean

pingInterval (common)

Ping interval to be aware if connection is still alive (in milliseconds)

4000

int

reconnect (common)

Whether or not using reconnection feature

true

boolean

reconnectTimeWait (common)

Waiting time before attempts reconnection (in milliseconds)

2000

int

topic (common)

Required The name of topic we want to use

 

String

verbose (common)

Whether or not running in verbose mode

false

boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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

maxMessages (consumer)

Stop receiving messages from a topic we are subscribing to after maxMessages

 

String

poolSize (consumer)

Consumer pool size

10

int

queueName (consumer)

The Queue name if we are using nats for a queue configuration

 

String

exceptionHandler (consumer)

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options 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)

Sets the exchange pattern when the consumer creates an exchange.

 

ExchangePattern

replySubject (producer)

the subject to which subscribers should send response

 

String

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

secure (security)

Set secure option indicating TLS is required

false

boolean

ssl (security)

Whether or not using SSL

false

boolean

sslContextParameters (security)

To configure security using SSLContextParameters

 

SSLContextParameters

tlsDebug (security)

TLS Debug, it will add additional console output

false

boolean

227.3. Headers

NameTypeDescription

CamelNatsMessageTimestamp

long

The timestamp of a consumed message.

CamelNatsSubscriptionId

Integer

The subscription ID of a consumer.

  Producer example:

from("direct:send").to("nats://localhost:4222?topic=test");

 

Consumer example:

from("nats://localhost:4222?topic=test&maxMessages=5&queueName=test").to("mock:result");