Pulsar
Since Camel 2.24
Both producer and consumer are supported
Maven users will need to add the following dependency to their pom.xml
for this component.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-pulsar</artifactId>
<!-- use the same version as your Camel core version -->
<version>x.y.z</version>
</dependency>
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for 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, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
Component Options
The Pulsar component supports 44 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
The Authentication FQCN to be used while creating the client from URI. | String | ||
The Authentication Parameters to be used while creating the client from URI. | String | ||
Allows to pre-configure the Pulsar component with common options that the endpoints will reuse. | PulsarConfiguration | ||
The Pulsar Service URL to point while creating the client from URI. | String | ||
Group the consumer acknowledgments for the specified time in milliseconds - defaults to 100. | 100 | long | |
Timeout for unacknowledged messages in milliseconds - defaults to 10000. | 10000 | long | |
RedeliveryBackoff to use for ack timeout redelivery backoff. | RedeliveryBackoff | ||
Whether to allow manual message acknowledgements. If this option is enabled, then messages are not acknowledged automatically after successful route completion. Instead, an instance of PulsarMessageReceipt is stored as a header on the org.apache.camel.Exchange. Messages can then be acknowledged using PulsarMessageReceipt at any time before the ackTimeout occurs. | false | boolean | |
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 | |
Name of the consumer when subscription is EXCLUSIVE. | sole-consumer | String | |
Prefix to add to consumer names when a SHARED or FAILOVER subscription is used. | cons | String | |
Size of the consumer queue - defaults to 10. | 10 | int | |
Name of the topic where the messages which fail maxRedeliverCount times will be sent. Note: if not set, default topic name will be topicName-subscriptionName-DLQ. | String | ||
Maximum number of times that a message will be redelivered before being sent to the dead letter queue. If this value is not set, no Dead Letter Policy will be created. | Integer | ||
Whether to use the messageListener interface, or to receive messages using a separate thread pool. | true | boolean | |
RedeliveryBackoff to use for negative ack redelivery backoff. | RedeliveryBackoff | ||
Set the negative acknowledgement delay. | 60000000 | long | |
Number of consumers - defaults to 1. | 1 | int | |
Number of threads to receive and handle messages when using a separate thread pool. | 1 | int | |
Enable compacted topic reading. | false | boolean | |
Control the initial position in the topic of a newly created subscription. Default is latest message. Enum values:
| LATEST | SubscriptionInitialPosition | |
Name of the subscription to use. | subs | String | |
Determines to which topics this consumer should be subscribed to - Persistent, Non-Persistent, or both. Only used with pattern subscriptions. Enum values:
| PersistentOnly | RegexSubscriptionMode | |
Type of the subscription EXCLUSIVESHAREDFAILOVERKEY_SHARED, defaults to EXCLUSIVE. Enum values:
| EXCLUSIVE | SubscriptionType | |
Whether the topic is a pattern (regular expression) that allows the consumer to subscribe to all matching topics in the namespace. | false | boolean | |
Provide a factory to create an alternate implementation of PulsarMessageReceipt. | PulsarMessageReceiptFactory | ||
Control batching method used by the producer. | DEFAULT | BatcherBuilder | |
Control whether automatic batching of messages is enabled for the producer. | true | boolean | |
The maximum size to batch messages. | 1000 | int | |
The maximum time period within which the messages sent will be batched if batchingEnabled is true. | 1000 | long | |
Whether to block the producing thread if pending messages queue is full or to throw a ProducerQueueIsFullError. | false | boolean | |
Control whether chunking of messages is enabled for the producer. | false | boolean | |
Compression type to use. Enum values:
| NONE | CompressionType | |
The first message published will have a sequence Id of initialSequenceId 1. | -1 | long | |
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 | |
Size of the pending massages queue. When the queue is full, by default, any further sends will fail unless blockIfQueueFull=true. | 1000 | int | |
Deprecated The maximum number of pending messages for partitioned topics. The maxPendingMessages value will be reduced if (number of partitions maxPendingMessages) exceeds this value. Partitioned topics have a pending message queue for each partition. | 50000 | int | |
Custom Message Router to use. | MessageRouter | ||
Message Routing Mode to use. Enum values:
| RoundRobinPartition | MessageRoutingMode | |
Name of the producer. If unset, lets Pulsar select a unique identifier. | String | ||
Send timeout in milliseconds. | 30000 | int | |
The pulsar auto configuration. | AutoConfiguration | ||
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 | |
Autowired The pulsar client. | PulsarClient |
Endpoint Options
The Pulsar endpoint is configured using URI syntax:
pulsar:persistence://tenant/namespace/topic
with the following path and query parameters:
Query Parameters (41 parameters)
Name | Description | Default | Type |
---|---|---|---|
The Authentication FQCN to be used while creating the client from URI. | String | ||
The Authentication Parameters to be used while creating the client from URI. | String | ||
The Pulsar Service URL to point while creating the client from URI. | String | ||
Group the consumer acknowledgments for the specified time in milliseconds - defaults to 100. | 100 | long | |
Timeout for unacknowledged messages in milliseconds - defaults to 10000. | 10000 | long | |
RedeliveryBackoff to use for ack timeout redelivery backoff. | RedeliveryBackoff | ||
Whether to allow manual message acknowledgements. If this option is enabled, then messages are not acknowledged automatically after successful route completion. Instead, an instance of PulsarMessageReceipt is stored as a header on the org.apache.camel.Exchange. Messages can then be acknowledged using PulsarMessageReceipt at any time before the ackTimeout occurs. | false | boolean | |
Name of the consumer when subscription is EXCLUSIVE. | sole-consumer | String | |
Prefix to add to consumer names when a SHARED or FAILOVER subscription is used. | cons | String | |
Size of the consumer queue - defaults to 10. | 10 | int | |
Name of the topic where the messages which fail maxRedeliverCount times will be sent. Note: if not set, default topic name will be topicName-subscriptionName-DLQ. | String | ||
Maximum number of times that a message will be redelivered before being sent to the dead letter queue. If this value is not set, no Dead Letter Policy will be created. | Integer | ||
Whether to use the messageListener interface, or to receive messages using a separate thread pool. | true | boolean | |
RedeliveryBackoff to use for negative ack redelivery backoff. | RedeliveryBackoff | ||
Set the negative acknowledgement delay. | 60000000 | long | |
Number of consumers - defaults to 1. | 1 | int | |
Number of threads to receive and handle messages when using a separate thread pool. | 1 | int | |
Enable compacted topic reading. | false | boolean | |
Control the initial position in the topic of a newly created subscription. Default is latest message. Enum values:
| LATEST | SubscriptionInitialPosition | |
Name of the subscription to use. | subs | String | |
Determines to which topics this consumer should be subscribed to - Persistent, Non-Persistent, or both. Only used with pattern subscriptions. Enum values:
| PersistentOnly | RegexSubscriptionMode | |
Type of the subscription EXCLUSIVESHAREDFAILOVERKEY_SHARED, defaults to EXCLUSIVE. Enum values:
| EXCLUSIVE | SubscriptionType | |
Whether the topic is a pattern (regular expression) that allows the consumer to subscribe to all matching topics in the namespace. | false | boolean | |
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 | |
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 | ||
Control batching method used by the producer. | DEFAULT | BatcherBuilder | |
Control whether automatic batching of messages is enabled for the producer. | true | boolean | |
The maximum size to batch messages. | 1000 | int | |
The maximum time period within which the messages sent will be batched if batchingEnabled is true. | 1000 | long | |
Whether to block the producing thread if pending messages queue is full or to throw a ProducerQueueIsFullError. | false | boolean | |
Control whether chunking of messages is enabled for the producer. | false | boolean | |
Compression type to use. Enum values:
| NONE | CompressionType | |
The first message published will have a sequence Id of initialSequenceId 1. | -1 | long | |
Size of the pending massages queue. When the queue is full, by default, any further sends will fail unless blockIfQueueFull=true. | 1000 | int | |
Deprecated The maximum number of pending messages for partitioned topics. The maxPendingMessages value will be reduced if (number of partitions maxPendingMessages) exceeds this value. Partitioned topics have a pending message queue for each partition. | 50000 | int | |
Custom Message Router to use. | MessageRouter | ||
Message Routing Mode to use. Enum values:
| RoundRobinPartition | MessageRoutingMode | |
Name of the producer. If unset, lets Pulsar select a unique identifier. | String | ||
Send timeout in milliseconds. | 30000 | int | |
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 Pulsar component supports 15 message header(s), which is/are listed below:
Name | Description | Default | Type |
---|---|---|---|
Constant: | The properties attached to the message. | Map | |
Constant: | The producer name who produced the message. | String | |
Constant: | The sequence id associated with the message. | long | |
Constant: | The publish time of the message. | long | |
Constant: | The unique message ID associated with the message. | MessageId | |
Constant: | The event time associated with the message. | long | |
Constant: | The key of the message. | String | |
Constant: | The bytes in key. | byte[] | |
Constant: | The topic the message was published to. | String | |
Constant: | The message receipt. | PulsarMessageReceipt | |
CamelPulsarProducerMessageKey (producer) Constant: | The key of the message for routing policy. | String | |
CamelPulsarProducerMessageProperties (producer) Constant: | The properties of the message to add. | Map | |
CamelPulsarProducerMessageEventTime (producer) Constant: | The event time of the message message. | Long | |
CamelPulsarProducerMessageDeliverAt (producer) Constant: | Deliver the message only at or after the specified absolute timestamp. The timestamp is milliseconds and based on UTC (eg: System.currentTimeMillis) Note: messages are only delivered with delay when a consumer is consuming through a Shared subscription. With other subscription types, the messages will still be delivered immediately. | Long | |
CamelPulsarRedeliveryCount (consumer) Constant: | The message redelivery count, redelivery count maintain in pulsar broker. | int |
Spring Boot Auto-Configuration
When using pulsar with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-pulsar-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 45 options, which are listed below.