Camel Components

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>

URI format

pulsar:[persistent|non-persistent]://tenant/namespace/topic

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, *.yaml files, 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 Pulsar component supports the following options which are listed below.

Name Description Default Type

authenticationClass (common)

The fully qualified class name of the Pulsar authentication plugin, such as org.apache.pulsar.client.impl.auth.AuthenticationToken. Only used together with authenticationParams, and not when a pulsarClient is given.

String

authenticationParams (common)

The parameters of the authentication plugin set in authenticationClass, as one string in the format that the plugin reads. Only used together with authenticationClass, and not when a pulsarClient is given.

String

configuration (common)

Allows to pre-configure the Pulsar component with common options that the endpoints will reuse.

PulsarConfiguration

serviceUrl (common)

The Pulsar service URL to connect to, such as pulsar://localhost:6650, or pulsar+ssl://host:6651 for TLS. Not used when a pulsarClient is given.

String

ackGroupTimeMillis (consumer)

The time in milliseconds during which the consumer groups the acknowledgements before it sends them to the broker. 0 sends each acknowledgement at once.

100

long

ackTimeoutMillis (consumer)

The time in milliseconds after which a message that is not acknowledged is redelivered. 0 turns the timeout off; any other value must be at least 1000.

10000

long

ackTimeoutRedeliveryBackoff (consumer)

A RedeliveryBackoff, such as a MultiplierRedeliveryBackoff, that gives the delay before a message whose ackTimeoutMillis expired is redelivered, from the number of times it was redelivered. Only used when ackTimeoutMillis is not 0.

RedeliveryBackoff

allowManualAcknowledgement (consumer)

Whether the route acknowledges the messages itself. When enabled, the consumer neither acknowledges nor negatively acknowledges a message after the route, and sets a PulsarMessageReceipt in the message_receipt header instead, to acknowledge the message with before ackTimeoutMillis expires.

false

boolean

bridgeErrorHandler (consumer)

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

consumerName (consumer)

The name of the consumer with the EXCLUSIVE subscription type. The name identifies the consumer, for example in the topic stats.

sole-consumer

String

consumerNamePrefix (consumer)

The prefix of the consumer names with the SHARED, FAILOVER and KEY_SHARED subscription types. Each consumer is named the prefix followed by its index, starting at 0.

cons

String

consumerQueueSize (consumer)

The size of the receiver queue of each consumer: how many messages the consumer fetches from the broker ahead of processing them. 0 turns prefetching off.

10

int

deadLetterTopic (consumer)

The name of the dead letter topic. Only used when maxRedeliverCount is set. If not set, the Pulsar client uses topicName-subscriptionName-DLQ.

String

enableBatchIndexAcknowledgment (consumer)

When enabled, allows each individual message in a batch to be acknowledged independently. By default Pulsar redelivers the entire batch when any single message in the batch is not acknowledged. This option also requires the Pulsar broker to be configured with acknowledgmentAtBatchIndexLevelEnabled=true.

false

boolean

enableRetry (consumer)

Whether to enable the retry letter topic mode of the Pulsar consumer: the consumer also subscribes to the retry letter topic, which receives the messages passed to Consumer.reconsumeLater. Camel itself negatively acknowledges a failed message and does not call reconsumeLater. If maxRedeliverCount is not set, the Pulsar client uses its default dead letter policy of 16 redeliveries.

false

boolean

keySharedPolicy (consumer)

The key shared policy of the consumers, for the KEY_SHARED subscription type. AUTO_SPLIT has the broker split the hash range of the message keys over the consumers. STICKY needs hash ranges assigned to each consumer, which Camel does not set, so the Pulsar client rejects it and the consumer fails to start.

Enum values:

  • AUTO_SPLIT

  • STICKY

String

maxRedeliverCount (consumer)

The number of redeliveries after which a message is sent to the dead letter topic instead. Must be greater than 0. If not set, Camel creates no dead letter policy, and deadLetterTopic and retryLetterTopic are not used.

Integer

messageListener (consumer)

Whether the Pulsar client delivers the messages to a message listener, on the listener threads of the client, or Camel receives them with a thread pool of its own of numberOfConsumerThreads threads for each consumer.

true

boolean

negativeAckRedeliveryBackoff (consumer)

A RedeliveryBackoff, such as a MultiplierRedeliveryBackoff, that gives the delay before a negatively acknowledged message is redelivered, from the number of times it was redelivered. When set, negativeAckRedeliveryDelayMicros is not used.

RedeliveryBackoff

negativeAckRedeliveryDelayMicros (consumer)

The delay in microseconds before a message that failed in the route (negatively acknowledged) is redelivered. The default is 1 minute. Not used when negativeAckRedeliveryBackoff is set.

60000000

long

numberOfConsumers (consumer)

The number of Pulsar consumers to subscribe with the SHARED, FAILOVER and KEY_SHARED subscription types. The EXCLUSIVE subscription type always uses one consumer.

1

int

numberOfConsumerThreads (consumer)

The number of threads that receive and process the messages of each consumer, when messageListener is disabled.

1

int

readCompacted (consumer)

Whether to read the compacted topic instead of its full backlog, so that up to the point of the last compaction only the latest message of each key is received. Only for persistent topics with the EXCLUSIVE or FAILOVER subscription type: with SHARED or KEY_SHARED the subscribe fails.

false

boolean

retryLetterTopic (consumer)

The name of the retry letter topic. Only used when enableRetry is enabled and maxRedeliverCount is set. If not set, the Pulsar client uses topicName-subscriptionName-RETRY.

String

subscriptionInitialPosition (consumer)

Where a new subscription starts: LATEST at the next message published, EARLIEST at the oldest message kept in the topic. Not used when the subscription already exists.

Enum values:

  • EARLIEST

  • LATEST

LATEST

SubscriptionInitialPosition

subscriptionMode (consumer)

Determines the subscription mode for the consumer. Durable subscriptions persist the cursor position if the consumer disconnects while non-durable subscriptions do not.

Enum values:

  • DURABLE

  • NON_DURABLE

DURABLE

SubscriptionMode

subscriptionName (consumer)

The name of the subscription. The broker creates the subscription when it does not exist yet.

subs

String

subscriptionTopicsMode (consumer)

Which topics a topicsPattern subscription covers: the persistent topics, the non-persistent topics, or all topics. Only used when topicsPattern is enabled.

Enum values:

  • PersistentOnly

  • NonPersistentOnly

  • AllTopics

PersistentOnly

RegexSubscriptionMode

subscriptionType (consumer)

The subscription type. EXCLUSIVE allows a single consumer on the subscription. SHARED spreads the messages over the consumers. FAILOVER delivers the messages to one active consumer, and the others take over when it disconnects. KEY_SHARED spreads the messages over the consumers by key, the messages of a key going to the same consumer.

Enum values:

  • EXCLUSIVE

  • SHARED

  • FAILOVER

  • KEY_SHARED

EXCLUSIVE

SubscriptionType

topicsPattern (consumer)

Whether the topic of the endpoint URI is a regular expression. The consumer then subscribes to all the topics of the namespace whose name matches it, also to the topics created later.

false

boolean

pulsarMessageReceiptFactory (consumer (advanced))

A factory that creates the PulsarMessageReceipt set in the message_receipt header when allowManualAcknowledgement is enabled, to provide an implementation other than the default.

PulsarMessageReceiptFactory

batcherBuilder (producer)

Control batching method used by the producer. DEFAULT batches the messages together regardless of their key. KEY_BASED batches the messages of each key separately, so that a Key_Shared subscription spreads the keys over its consumers. A custom BatcherBuilder can be given as a bean reference.

Enum values:

  • DEFAULT

  • KEY_BASED

DEFAULT

BatcherBuilder

batchingEnabled (producer)

Whether the producer groups the messages into batches. Must be disabled to use chunkingEnabled.

true

boolean

batchingMaxMessages (producer)

The maximum number of messages in a batch. Currently not passed to the Pulsar client: the producer uses the maxPendingMessages value as the maximum number of messages in a batch.

1000

int

batchingMaxPublishDelayMicros (producer)

The maximum time in microseconds that the producer holds the messages to send them in one batch, when batchingEnabled is true. Must be at least 1000 (1 millisecond).

1000

long

blockIfQueueFull (producer)

Whether a send waits when the queue of pending messages (maxPendingMessages) is full, instead of failing with a ProducerQueueIsFullError.

false

boolean

chunkingEnabled (producer)

Whether the producer splits a message that is larger than the maximum message size of the broker into chunks, which the consumer joins again. Requires batchingEnabled to be false, otherwise the producer fails to start.

false

boolean

compressionType (producer)

The compression type of the message payloads.

Enum values:

  • NONE

  • LZ4

  • ZLIB

  • ZSTD

  • SNAPPY

NONE

CompressionType

hashingScheme (producer)

The hash function of the message key that chooses the partition of a message with a key, with the RoundRobinPartition and SinglePartition routing modes.

Enum values:

  • JavaStringHash

  • Murmur3_32Hash

JavaStringHash

String

initialSequenceId (producer)

The first message published will have a sequence Id of initialSequenceId plus one. The default -1 leaves it to the Pulsar client, which continues after the last sequence id the broker has for the producer name.

-1

long

lazyStartProducer (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

maxPendingMessages (producer)

The maximum number of sent messages that wait for the acknowledgement of the broker. When the queue is full, a send fails, unless blockIfQueueFull is enabled. 0 means no limit. Must not be greater than maxPendingMessagesAcrossPartitions.

1000

int

maxPendingMessagesAcrossPartitions (producer)

Deprecated The maximum number of pending messages across all the partitions of a partitioned topic, each partition having its own queue of pending messages. The maxPendingMessages value is reduced if (number of partitions * maxPendingMessages) exceeds this value. Must be at least maxPendingMessages.

50000

int

messageRouter (producer)

A custom MessageRouter that chooses the partition of a partitioned topic for each message. When set, messageRoutingMode is not used.

MessageRouter

messageRoutingMode (producer)

How the producer chooses the partition of a partitioned topic for a message without a key: RoundRobinPartition spreads the messages over all the partitions, SinglePartition sends them all to one partition picked at random, and CustomPartition uses the messageRouter, which it requires. A message with a key goes to the partition given by the hash of its key (hashingScheme). Not used when messageRouter is set.

Enum values:

  • SinglePartition

  • RoundRobinPartition

  • CustomPartition

RoundRobinPartition

MessageRoutingMode

producerName (producer)

Name of the producer. If unset, lets Pulsar select a unique identifier.

String

sendTimeoutMs (producer)

The time in milliseconds within which the broker must acknowledge a sent message, otherwise the send fails. 0 means no timeout.

30000

int

allowJavaSerializedObject (producer (advanced))

Deprecated Whether the producer sends a body that does not convert to a byte array (such as a Map, a List, a number or a POJO) with Java serialization, as Camel did before 4.24. Such a message can only be read by a Java client that deserializes it. By default the producer fails such a body: marshal it first, for example to JSON. Deprecation note: Java serialization of the body is kept only for compatibility, and will be removed: marshal the body before sending it.

false

boolean

autoConfiguration (advanced)

An AutoConfiguration that, when an endpoint is created, creates its tenant and namespace with the Pulsar admin client if they do not exist yet. A failure is only logged.

AutoConfiguration

autowiredEnabled (advanced)

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

pulsarClient (advanced)

Autowired The Pulsar client that all the endpoints use. When set, the endpoints do not create a client of their own, and serviceUrl, the authentication options and the TLS options are not used.

PulsarClient

hostnameVerification (security)

Whether to check that the certificate of the broker matches the host Camel connects to, with pulsar+ssl://. When disabled, any certificate trusted by the client is accepted, whatever host it was issued for. Not used when a pulsarClient is given.

true

boolean

tlsTrustCertsFilePath (security)

The path of a PEM file with the certificates of the certificate authorities to trust, for a broker on pulsar+ssl:// whose certificate is not signed by an authority that the JVM trusts. Not used when a pulsarClient is given.

String

Endpoint Options

The Pulsar endpoint is configured using URI syntax:

pulsar:persistence://tenant/namespace/topic

With the following path and query parameters:

Path Parameters

Name Description Default Type

persistence (common)

Required Whether the topic is persistent (its messages are stored by the broker) or non-persistent (its messages are only kept in memory, and only delivered to the consumers connected at the time).

Enum values:

  • persistent

  • non-persistent

String

tenant (common)

Required The Pulsar tenant of the topic.

String

namespace (common)

Required The namespace of the topic, within the tenant.

String

topic (common)

Required The name of the topic. With the topicsPattern option, a regular expression that the names of the topics of the namespace must match.

String

Query Parameters

Name Description Default Type

authenticationClass (common)

The fully qualified class name of the Pulsar authentication plugin, such as org.apache.pulsar.client.impl.auth.AuthenticationToken. Only used together with authenticationParams, and not when a pulsarClient is given.

String

authenticationParams (common)

The parameters of the authentication plugin set in authenticationClass, as one string in the format that the plugin reads. Only used together with authenticationClass, and not when a pulsarClient is given.

String

serviceUrl (common)

The Pulsar service URL to connect to, such as pulsar://localhost:6650, or pulsar+ssl://host:6651 for TLS. Not used when a pulsarClient is given.

String

ackGroupTimeMillis (consumer)

The time in milliseconds during which the consumer groups the acknowledgements before it sends them to the broker. 0 sends each acknowledgement at once.

100

long

ackTimeoutMillis (consumer)

The time in milliseconds after which a message that is not acknowledged is redelivered. 0 turns the timeout off; any other value must be at least 1000.

10000

long

ackTimeoutRedeliveryBackoff (consumer)

A RedeliveryBackoff, such as a MultiplierRedeliveryBackoff, that gives the delay before a message whose ackTimeoutMillis expired is redelivered, from the number of times it was redelivered. Only used when ackTimeoutMillis is not 0.

RedeliveryBackoff

allowManualAcknowledgement (consumer)

Whether the route acknowledges the messages itself. When enabled, the consumer neither acknowledges nor negatively acknowledges a message after the route, and sets a PulsarMessageReceipt in the message_receipt header instead, to acknowledge the message with before ackTimeoutMillis expires.

false

boolean

consumerName (consumer)

The name of the consumer with the EXCLUSIVE subscription type. The name identifies the consumer, for example in the topic stats.

sole-consumer

String

consumerNamePrefix (consumer)

The prefix of the consumer names with the SHARED, FAILOVER and KEY_SHARED subscription types. Each consumer is named the prefix followed by its index, starting at 0.

cons

String

consumerQueueSize (consumer)

The size of the receiver queue of each consumer: how many messages the consumer fetches from the broker ahead of processing them. 0 turns prefetching off.

10

int

deadLetterTopic (consumer)

The name of the dead letter topic. Only used when maxRedeliverCount is set. If not set, the Pulsar client uses topicName-subscriptionName-DLQ.

String

enableBatchIndexAcknowledgment (consumer)

When enabled, allows each individual message in a batch to be acknowledged independently. By default Pulsar redelivers the entire batch when any single message in the batch is not acknowledged. This option also requires the Pulsar broker to be configured with acknowledgmentAtBatchIndexLevelEnabled=true.

false

boolean

enableRetry (consumer)

Whether to enable the retry letter topic mode of the Pulsar consumer: the consumer also subscribes to the retry letter topic, which receives the messages passed to Consumer.reconsumeLater. Camel itself negatively acknowledges a failed message and does not call reconsumeLater. If maxRedeliverCount is not set, the Pulsar client uses its default dead letter policy of 16 redeliveries.

false

boolean

keySharedPolicy (consumer)

The key shared policy of the consumers, for the KEY_SHARED subscription type. AUTO_SPLIT has the broker split the hash range of the message keys over the consumers. STICKY needs hash ranges assigned to each consumer, which Camel does not set, so the Pulsar client rejects it and the consumer fails to start.

Enum values:

  • AUTO_SPLIT

  • STICKY

String

maxRedeliverCount (consumer)

The number of redeliveries after which a message is sent to the dead letter topic instead. Must be greater than 0. If not set, Camel creates no dead letter policy, and deadLetterTopic and retryLetterTopic are not used.

Integer

messageListener (consumer)

Whether the Pulsar client delivers the messages to a message listener, on the listener threads of the client, or Camel receives them with a thread pool of its own of numberOfConsumerThreads threads for each consumer.

true

boolean

negativeAckRedeliveryBackoff (consumer)

A RedeliveryBackoff, such as a MultiplierRedeliveryBackoff, that gives the delay before a negatively acknowledged message is redelivered, from the number of times it was redelivered. When set, negativeAckRedeliveryDelayMicros is not used.

RedeliveryBackoff

negativeAckRedeliveryDelayMicros (consumer)

The delay in microseconds before a message that failed in the route (negatively acknowledged) is redelivered. The default is 1 minute. Not used when negativeAckRedeliveryBackoff is set.

60000000

long

numberOfConsumers (consumer)

The number of Pulsar consumers to subscribe with the SHARED, FAILOVER and KEY_SHARED subscription types. The EXCLUSIVE subscription type always uses one consumer.

1

int

numberOfConsumerThreads (consumer)

The number of threads that receive and process the messages of each consumer, when messageListener is disabled.

1

int

readCompacted (consumer)

Whether to read the compacted topic instead of its full backlog, so that up to the point of the last compaction only the latest message of each key is received. Only for persistent topics with the EXCLUSIVE or FAILOVER subscription type: with SHARED or KEY_SHARED the subscribe fails.

false

boolean

retryLetterTopic (consumer)

The name of the retry letter topic. Only used when enableRetry is enabled and maxRedeliverCount is set. If not set, the Pulsar client uses topicName-subscriptionName-RETRY.

String

subscriptionInitialPosition (consumer)

Where a new subscription starts: LATEST at the next message published, EARLIEST at the oldest message kept in the topic. Not used when the subscription already exists.

Enum values:

  • EARLIEST

  • LATEST

LATEST

SubscriptionInitialPosition

subscriptionMode (consumer)

Determines the subscription mode for the consumer. Durable subscriptions persist the cursor position if the consumer disconnects while non-durable subscriptions do not.

Enum values:

  • DURABLE

  • NON_DURABLE

DURABLE

SubscriptionMode

subscriptionName (consumer)

The name of the subscription. The broker creates the subscription when it does not exist yet.

subs

String

subscriptionTopicsMode (consumer)

Which topics a topicsPattern subscription covers: the persistent topics, the non-persistent topics, or all topics. Only used when topicsPattern is enabled.

Enum values:

  • PersistentOnly

  • NonPersistentOnly

  • AllTopics

PersistentOnly

RegexSubscriptionMode

subscriptionType (consumer)

The subscription type. EXCLUSIVE allows a single consumer on the subscription. SHARED spreads the messages over the consumers. FAILOVER delivers the messages to one active consumer, and the others take over when it disconnects. KEY_SHARED spreads the messages over the consumers by key, the messages of a key going to the same consumer.

Enum values:

  • EXCLUSIVE

  • SHARED

  • FAILOVER

  • KEY_SHARED

EXCLUSIVE

SubscriptionType

topicsPattern (consumer)

Whether the topic of the endpoint URI is a regular expression. The consumer then subscribes to all the topics of the namespace whose name matches it, also to the topics created later.

false

boolean

bridgeErrorHandler (consumer (advanced))

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

exceptionHandler (consumer (advanced))

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

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

batcherBuilder (producer)

Control batching method used by the producer. DEFAULT batches the messages together regardless of their key. KEY_BASED batches the messages of each key separately, so that a Key_Shared subscription spreads the keys over its consumers. A custom BatcherBuilder can be given as a bean reference.

Enum values:

  • DEFAULT

  • KEY_BASED

DEFAULT

BatcherBuilder

batchingEnabled (producer)

Whether the producer groups the messages into batches. Must be disabled to use chunkingEnabled.

true

boolean

batchingMaxMessages (producer)

The maximum number of messages in a batch. Currently not passed to the Pulsar client: the producer uses the maxPendingMessages value as the maximum number of messages in a batch.

1000

int

batchingMaxPublishDelayMicros (producer)

The maximum time in microseconds that the producer holds the messages to send them in one batch, when batchingEnabled is true. Must be at least 1000 (1 millisecond).

1000

long

blockIfQueueFull (producer)

Whether a send waits when the queue of pending messages (maxPendingMessages) is full, instead of failing with a ProducerQueueIsFullError.

false

boolean

chunkingEnabled (producer)

Whether the producer splits a message that is larger than the maximum message size of the broker into chunks, which the consumer joins again. Requires batchingEnabled to be false, otherwise the producer fails to start.

false

boolean

compressionType (producer)

The compression type of the message payloads.

Enum values:

  • NONE

  • LZ4

  • ZLIB

  • ZSTD

  • SNAPPY

NONE

CompressionType

hashingScheme (producer)

The hash function of the message key that chooses the partition of a message with a key, with the RoundRobinPartition and SinglePartition routing modes.

Enum values:

  • JavaStringHash

  • Murmur3_32Hash

JavaStringHash

String

initialSequenceId (producer)

The first message published will have a sequence Id of initialSequenceId plus one. The default -1 leaves it to the Pulsar client, which continues after the last sequence id the broker has for the producer name.

-1

long

maxPendingMessages (producer)

The maximum number of sent messages that wait for the acknowledgement of the broker. When the queue is full, a send fails, unless blockIfQueueFull is enabled. 0 means no limit. Must not be greater than maxPendingMessagesAcrossPartitions.

1000

int

maxPendingMessagesAcrossPartitions (producer)

Deprecated The maximum number of pending messages across all the partitions of a partitioned topic, each partition having its own queue of pending messages. The maxPendingMessages value is reduced if (number of partitions * maxPendingMessages) exceeds this value. Must be at least maxPendingMessages.

50000

int

messageRouter (producer)

A custom MessageRouter that chooses the partition of a partitioned topic for each message. When set, messageRoutingMode is not used.

MessageRouter

messageRoutingMode (producer)

How the producer chooses the partition of a partitioned topic for a message without a key: RoundRobinPartition spreads the messages over all the partitions, SinglePartition sends them all to one partition picked at random, and CustomPartition uses the messageRouter, which it requires. A message with a key goes to the partition given by the hash of its key (hashingScheme). Not used when messageRouter is set.

Enum values:

  • SinglePartition

  • RoundRobinPartition

  • CustomPartition

RoundRobinPartition

MessageRoutingMode

producerName (producer)

Name of the producer. If unset, lets Pulsar select a unique identifier.

String

sendTimeoutMs (producer)

The time in milliseconds within which the broker must acknowledge a sent message, otherwise the send fails. 0 means no timeout.

30000

int

allowJavaSerializedObject (producer (advanced))

Deprecated Whether the producer sends a body that does not convert to a byte array (such as a Map, a List, a number or a POJO) with Java serialization, as Camel did before 4.24. Such a message can only be read by a Java client that deserializes it. By default the producer fails such a body: marshal it first, for example to JSON. Deprecation note: Java serialization of the body is kept only for compatibility, and will be removed: marshal the body before sending it.

false

boolean

lazyStartProducer (producer (advanced))

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

hostnameVerification (security)

Whether to check that the certificate of the broker matches the host Camel connects to, with pulsar+ssl://. When disabled, any certificate trusted by the client is accepted, whatever host it was issued for. Not used when a pulsarClient is given.

true

boolean

tlsTrustCertsFilePath (security)

The path of a PEM file with the certificates of the certificate authorities to trust, for a broker on pulsar+ssl:// whose certificate is not signed by an authority that the JVM trusts. Not used when a pulsarClient is given.

String

Message Headers

The Pulsar component supports the following message header(s), which is/are listed below:

Name Description Default Type

properties (consumer)

Constant: PROPERTIES

The properties attached to the message.

Map

producer_name (consumer)

Constant: PRODUCER_NAME

The name of the producer that published the message.

String

sequence_id (consumer)

Constant: SEQUENCE_ID

The sequence id associated with the message.

long

publish_time (consumer)

Constant: PUBLISH_TIME

The time the message was published, in milliseconds since the epoch.

long

message_id (consumer)

Constant: MESSAGE_ID

The unique message ID associated with the message.

MessageId

event_time (consumer)

Constant: EVENT_TIME

The event time the producer set on the message, in milliseconds since the epoch, or 0 when none was set.

long

key (consumer)

Constant: KEY

The key of the message, or null when it has none.

String

key_bytes (consumer)

Constant: KEY_BYTES

The key of the message as bytes: decoded when the key is Base64 encoded, otherwise the UTF-8 bytes of the key. Null when the message has no key.

byte[]

topic_name (consumer)

Constant: TOPIC_NAME

The full name of the topic the message was published to, which tells the topics of a topicsPattern subscription apart.

String

message_receipt (consumer)

Constant: MESSAGE_RECEIPT

The PulsarMessageReceipt to acknowledge the message with. Only set when allowManualAcknowledgement is enabled.

PulsarMessageReceipt

CamelPulsarProducerMessageKey (producer)

Constant: KEY_OUT

The key of the message to send. It chooses the partition of a partitioned topic, and the consumer of a Key_Shared subscription.

String

CamelPulsarProducerMessageProperties (producer)

Constant: PROPERTIES_OUT

The properties to attach to the message to send.

Map

CamelPulsarProducerMessageEventTime (producer)

Constant: EVENT_TIME_OUT

The event time of the message to send, in milliseconds since the epoch.

Long

CamelPulsarProducerMessageDeliverAt (producer)

Constant: DELIVER_AT_OUT

Deliver the message only at or after this time, in milliseconds since the epoch (as System.currentTimeMillis). The delay only applies to the consumers of a Shared or Key_Shared subscription; other subscription types receive the message at once.

Long

CamelPulsarRedeliveryCount (consumer)

Constant: PULSAR_REDELIVERY_COUNT

How many times the broker has redelivered the message, as counted by the broker: 0 on the first delivery.

int

CamelPulsarProducerMessageDeliverAfter (producer)

Constant: DELIVER_AFTER

Deliver the message only after this delay, in milliseconds. The delay only applies to the consumers of a Shared or Key_Shared subscription; other subscription types receive the message at once.

Long

CamelPulsarProducerMessageId (producer)

Constant: PRODUCER_MESSAGE_ID

The message id the broker assigned to the published message.

MessageId

CamelMessageTimestamp (consumer)

Constant: MESSAGE_TIMESTAMP

The time the message was published, in milliseconds since the epoch: the same value as publish_time.

long

Message Body

The message body at each side of the Pulsar 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

bytes or null (byte[])

The payload of the Pulsar message as a byte array, null for a message with a null value (a tombstone), with the key and the properties in headers: convert or unmarshal it.

Producer input

text, bytes, stream or file

What converts to a byte array: text, bytes, a stream or a file, sent as the payload. Any other body, such as a Map, a List, a number or a POJO, fails, and so does no body: marshal it first.

Not known when allowJavaSerializedObject is set.

Producer output

unchanged

Unchanged, also when the exchange expects a reply, with the id of the published message in a header.

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.

Deterministic simulation tests

The consumer of the Pulsar component is tested with deterministic simulation tests: the real consumer runs under a seeded virtual-time scheduler against a fake of the external system, which injects faults while the tests check invariants. A failing seed can be replayed. These are the fake worlds of the component:

World What it checks Issues

PulsarWorld

Fake: FakePulsar: a broker and client for one topic and one durable subscription

Tests: PulsarConsumerDstTest

Covers:

  • subscription types Exclusive, Shared, Failover and Key_Shared with one to three consumers

  • the message listener (messageListener=true, one consumer thread)

  • the ack timeout and the redelivery of a failed exchange after a negative acknowledgement

  • route start, restart, suspend and resume

  • an asynchronous downstream step

Faults:

  • subscribe fails (the broker cannot be reached before the operation timeout)

  • the broker restarts

  • the downstream step answers slowly

  • the downstream step fails

Invariants:

  • no unexpected client call or consumer count

  • the route is started

  • a started route holds the configured number of Pulsar consumers

  • every offered message is routed at least once

  • the subscription is drained once the faults cleared

The worlds and their tests are in the test sources of the component. How to run them, replay a seed and write a world is described in Running the tests and Writing a fake world.

Usage

Set the service URL of the Pulsar cluster on the component, for example in application.properties:

camel.component.pulsar.service-url = pulsar://localhost:6650

The following routes send a message to the orders topic every five seconds, and consume the topic with the order-processor subscription:

- route:
    from:
      uri: timer:orders
      parameters:
        period: 5000
      steps:
        - setBody:
            expression:
              simple:
                expression: "Order ${exchangeId}"
        - to:
            uri: pulsar:persistent://public/default/orders
- route:
    from:
      uri: pulsar:persistent://public/default/orders
      parameters:
        subscriptionName: order-processor
      steps:
        - log:
            message: "Received ${body}"

Message body

The producer sends the body as a byte array: text, bytes, a stream or a file are sent as their content. A body that does not convert to a byte array, such as a Map, a List, a number or a POJO, fails, and so does no body: marshal it first, for example to JSON with marshal().json(). The consumer gives the payload as a byte array, so convert or unmarshal it in the route.

Before Camel 4.24 such a body was sent with Java serialization, which only a Java client that deserializes it can read. The deprecated allowJavaSerializedObject option turns this back on for compatibility, and will be removed.

Producer sequence ids and deduplication

With a producerName and deduplication enabled on the broker, the producer continues the sequence ids after the last sequence id the broker stored for that producer name, also after a restart, so the broker does not drop the messages of the new run as duplicates. Set initialSequenceId only to start from a given sequence id: every start then begins after that value again, so with a producerName and deduplication the broker drops the messages until their sequence ids pass the last one it stored. Leave the option unset to let the client continue.