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
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,*.yamlfiles, 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 |
|---|---|---|---|
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 | ||
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 | ||
Allows to pre-configure the Pulsar component with common options that the endpoints will reuse. | PulsarConfiguration | ||
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 | ||
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 | |
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 | |
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 | ||
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 | |
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 | |
The name of the consumer with the EXCLUSIVE subscription type. The name identifies the consumer, for example in the topic stats. | sole-consumer | String | |
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 | |
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 | |
The name of the dead letter topic. Only used when maxRedeliverCount is set. If not set, the Pulsar client uses topicName-subscriptionName-DLQ. | String | ||
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 | |
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 | |
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:
| String | ||
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 | ||
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 | |
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 | ||
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 | |
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 | |
The number of threads that receive and process the messages of each consumer, when messageListener is disabled. | 1 | int | |
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 | |
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 | ||
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:
| LATEST | SubscriptionInitialPosition | |
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 | SubscriptionMode | |
The name of the subscription. The broker creates the subscription when it does not exist yet. | subs | String | |
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 | RegexSubscriptionMode | |
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 | SubscriptionType | |
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 | |
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 | ||
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 | BatcherBuilder | |
Whether the producer groups the messages into batches. Must be disabled to use chunkingEnabled. | true | boolean | |
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 | |
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 | |
Whether a send waits when the queue of pending messages (maxPendingMessages) is full, instead of failing with a ProducerQueueIsFullError. | false | boolean | |
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 | |
The compression type of the message payloads. Enum values:
| NONE | CompressionType | |
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 | String | |
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 | |
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 | |
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 | |
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 | |
A custom MessageRouter that chooses the partition of a partitioned topic for each message. When set, messageRoutingMode is not used. | MessageRouter | ||
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:
| RoundRobinPartition | MessageRoutingMode | |
Name of the producer. If unset, lets Pulsar select a unique identifier. | String | ||
The time in milliseconds within which the broker must acknowledge a sent message, otherwise the send fails. 0 means no timeout. | 30000 | int | |
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 | |
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 | ||
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 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 | ||
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 | |
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 |
|---|---|---|---|
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:
| String | ||
Required The Pulsar tenant of the topic. | String | ||
Required The namespace of the topic, within the tenant. | String | ||
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 |
|---|---|---|---|
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 | ||
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 | ||
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 | ||
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 | |
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 | |
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 | ||
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 | |
The name of the consumer with the EXCLUSIVE subscription type. The name identifies the consumer, for example in the topic stats. | sole-consumer | String | |
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 | |
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 | |
The name of the dead letter topic. Only used when maxRedeliverCount is set. If not set, the Pulsar client uses topicName-subscriptionName-DLQ. | String | ||
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 | |
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 | |
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:
| String | ||
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 | ||
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 | |
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 | ||
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 | |
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 | |
The number of threads that receive and process the messages of each consumer, when messageListener is disabled. | 1 | int | |
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 | |
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 | ||
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:
| LATEST | SubscriptionInitialPosition | |
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 | SubscriptionMode | |
The name of the subscription. The broker creates the subscription when it does not exist yet. | subs | String | |
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 | RegexSubscriptionMode | |
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 | SubscriptionType | |
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 | |
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 | |
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 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 | BatcherBuilder | |
Whether the producer groups the messages into batches. Must be disabled to use chunkingEnabled. | true | boolean | |
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 | |
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 | |
Whether a send waits when the queue of pending messages (maxPendingMessages) is full, instead of failing with a ProducerQueueIsFullError. | false | boolean | |
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 | |
The compression type of the message payloads. Enum values:
| NONE | CompressionType | |
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 | String | |
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 | |
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 | |
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 | |
A custom MessageRouter that chooses the partition of a partitioned topic for each message. When set, messageRoutingMode is not used. | MessageRouter | ||
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:
| RoundRobinPartition | MessageRoutingMode | |
Name of the producer. If unset, lets Pulsar select a unique identifier. | String | ||
The time in milliseconds within which the broker must acknowledge a sent message, otherwise the send fails. 0 means no timeout. | 30000 | int | |
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 | |
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 | |
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 | |
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 |
|---|---|---|---|
| Constant: | The properties attached to the message. | Map | |
| Constant: | The name of the producer that published the message. | String | |
| Constant: | The sequence id associated with the message. | long | |
| Constant: | The time the message was published, in milliseconds since the epoch. | long | |
| Constant: | The unique message ID associated with the message. | MessageId | |
| Constant: | The event time the producer set on the message, in milliseconds since the epoch, or 0 when none was set. | long | |
| Constant: | The key of the message, or null when it has none. | String | |
| Constant: | 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[] | |
| Constant: | The full name of the topic the message was published to, which tells the topics of a topicsPattern subscription apart. | String | |
| Constant: | The PulsarMessageReceipt to acknowledge the message with. Only set when allowManualAcknowledgement is enabled. | PulsarMessageReceipt | |
CamelPulsarProducerMessageKey (producer) Constant: | 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: | The properties to attach to the message to send. | Map | |
CamelPulsarProducerMessageEventTime (producer) Constant: | The event time of the message to send, in milliseconds since the epoch. | Long | |
CamelPulsarProducerMessageDeliverAt (producer) Constant: | 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: | How many times the broker has redelivered the message, as counted by the broker: 0 on the first delivery. | int | |
CamelPulsarProducerMessageDeliverAfter (producer) Constant: | 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: | The message id the broker assigned to the published message. | MessageId | |
CamelMessageTimestamp (consumer) Constant: | 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 |
| 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 |
| 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 |
Producer output |
| 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 |
|---|---|---|
Fake: FakePulsar: a broker and client for one topic and one durable subscription Tests: | Covers:
Faults:
Invariants:
|
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.