Azure ServiceBus
Since Camel 3.12
Both producer and consumer are supported
The azure-servicebus component that integrates Azure ServiceBus. Azure ServiceBus is a fully managed enterprise integration message broker. Service Bus can decouple applications and services. Service Bus offers a reliable and secure platform for asynchronous transfer of data and state. Data is transferred between different applications and services using messages.
Prerequisites
You must have an Azure Service Bus namespace. More information is available at Azure Documentation Portal.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-azure-servicebus</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core 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 Azure ServiceBus component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The AmqpRetryOptions of the Service Bus clients: the retry mode, the maximum number of retries, the delay and maximum delay between retries, and the try timeout of an operation. When not set, the SDK retries 3 times with an exponential delay from 0.8 seconds up to 1 minute, and a try timeout of 60 seconds. | AmqpRetryOptions | ||
The AmqpTransportType of the connection to Service Bus: AMQP (AMQP over TLS on port 5671) or AMQP_WEB_SOCKETS (AMQP over web sockets on port 443, needed with proxyOptions or when port 5671 is blocked). Enum values:
| AMQP | AmqpTransportType | |
The ClientOptions of the Service Bus clients: the application id that is sent in the user agent, and the tracing and metrics options. An AmqpClientOptions also sets the identifier of the clients. | ClientOptions | ||
The configuration that the endpoints of this component start from: each endpoint uses a copy of it, with the options of its URI set on top. | ServiceBusConfiguration | ||
The HeaderFilterStrategy that decides which Camel message headers the producer sends as application properties of the message, and which application properties of a received message the consumer sets as headers. The default leaves out names that start with Camel or camel, and the producer sends only headers with a value of type String, Boolean, Byte, Short, Integer, Long, Float, Double, Character, Date or UUID. | HeaderFilterStrategy | ||
The ProxyOptions of the proxy to connect to Service Bus through, for the producer and the consumer. A proxy needs amqpTransportType AMQP_WEB_SOCKETS: with AMQP the client fails to build. When not set, the SDK uses a proxy from its environment configuration, if one is configured. | ProxyOptions | ||
Required Whether topicOrQueueName is the name of a queue or of a topic. The consumer of a topic receives from the subscription set in subscriptionName. Enum values:
| queue | ServiceBusType | |
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 | |
Dead-letters the message of a failed exchange instead of abandoning it, with the exception as the dead-letter reason and its stack trace as the error description. The message goes to the dead-letter queue of the queue or subscription it was received from. Applies only in PEEK_LOCK receive mode, and not when reading a sub-queue (subQueue), where the message is abandoned. | false | boolean | |
How long the consumer keeps renewing the lock of a message while its exchange is in progress, in PEEK_LOCK receive mode, as a duration (such as 10m or PT10M) or in milliseconds. The lock is renewed shortly before it expires, until the exchange completes or this time has passed. 0 turns renewal off, so Service Bus delivers a message again when its exchange takes longer than the lock duration of the queue or subscription. With sessionEnabled, it is how long the SDK keeps renewing the session lock instead. Not used in RECEIVE_AND_DELETE receive mode. | 300000 | long | |
The maximum number of messages that the processor client hands to the route at the same time (concurrent calls of its message callback), at least 1. With sessionEnabled it is per session, so up to maxConcurrentSessions times maxConcurrentCalls messages. A call ends when the route continues asynchronously, so an asynchronous route can have more exchanges in flight. | 1 | int | |
The maximum number of sessions the consumer processes at the same time, each with up to maxConcurrentCalls messages at the same time. Only used when sessionEnabled is true. | 1 | int | |
The number of messages the processor client fetches from Service Bus ahead of the ones it is processing. 0 (the default) turns prefetch off: the consumer asks for a message only when a call is free to process it. In PEEK_LOCK receive mode, the lock of a prefetched message already runs while the message waits in the buffer. | int | ||
Autowired A ServiceBusProcessorClient to use instead of one that the consumer builds. The consumer only starts it, and stops it (without closing it) when the consumer stops: the client hands its messages to the processMessage callback it was built with, not to the route, and the consumer options (such as serviceBusReceiveMode, maxAutoLockRenewDuration or enableDeadLettering) do not apply to it. | ServiceBusProcessorClient | ||
How the consumer receives messages. PEEK_LOCK: Service Bus locks each message, and the consumer completes it when its exchange succeeds, or abandons it (dead-letters it with enableDeadLettering) when the exchange fails, so that Service Bus delivers it again, up to the maximum delivery count of the queue or subscription. RECEIVE_AND_DELETE: Service Bus deletes each message when it delivers it, so the message of a failed exchange is lost. Enum values:
| PEEK_LOCK | ServiceBusReceiveMode | |
Whether the consumer receives from a session-enabled queue or subscription, with a session processor client: it locks a session and receives the messages of that session in order, up to maxConcurrentSessions sessions at the same time. Needed to receive from a session-enabled queue or subscription. | false | boolean | |
How long a session-enabled consumer waits for the next message of a session before it closes the session and tries to lock another one, as a duration (such as 30s or PT30S) or in milliseconds. 0 or less (the default is -1) keeps the default of the Service Bus SDK. Only used when sessionEnabled is true. An idle session holds one of the maxConcurrentSessions slots for this long, so use a value that just covers the slowest asynchronous route. | -1 | long | |
The sub-queue of the queue or subscription to receive from: DEAD_LETTER_QUEUE (the dead-letter queue) or TRANSFER_DEAD_LETTER_QUEUE (the transfer dead-letter queue). When not set, or NONE, the consumer receives from the queue or subscription itself. Enum values:
| SubQueue | ||
Sets the name of the subscription in the topic to listen to. topicOrQueueName and serviceBusType=topic must also be set. This property is required if serviceBusType=topic and the consumer is in use. | String | ||
Whether the producer sends the body as bytes: a stream or a file (File or Path) as read, and any other body converted to byte[]. When false, the body is converted to a String. A BinaryData body is sent as it is either way. Applies to each element of a List body too. | 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 | |
The operation of the producer: sendMessages sends the message (or each element of a List body) at once, scheduleMessages schedules it to be enqueued at scheduledEnqueueTime. The CamelAzureServiceBusProducerOperation header overrides it. Enum values:
| sendMessages | ServiceBusProducerOperationDefinition | |
Sets OffsetDateTime at which the message should appear in the Service Bus queue or topic. Used only by the scheduleMessages producer operation; sendMessages sends the message at once. In an endpoint URI or a property use an ISO-8601 date-time with an offset, such as 2026-11-18T22:00:00Z or 2026-11-18T23:00:00+01:00. | OffsetDateTime | ||
Autowired A ServiceBusSenderClient to use instead of one that the producer builds. It sends to the queue or topic it was built for, so the connection options (such as connectionString, serviceBusType and topicOrQueueName) do not apply to it, and the producer does not close it. | ServiceBusSenderClient | ||
The ServiceBusTransactionContext (the id of a transaction created with createTransaction() of a Service Bus client) to send or schedule the messages in. The producer does not commit or roll back the transaction. The CamelAzureServiceBusServiceBusTransactionContext header overrides it. | ServiceBusTransactionContext | ||
The session id that the producer sets on every message it sends, as a session-enabled queue or topic needs one. The CamelAzureServiceBusSessionId header is not used. | String | ||
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 | |
Sets the connection string for a Service Bus namespace or a specific Service Bus resource. Connection strings commonly contain characters with a special meaning in URIs (the SharedAccessKey is a Base64 value that may contain plus, slash or equals characters): when configuring the connection string directly in an endpoint URI, wrap the value with RAW() so it is not URI-decoded. | String | ||
Determines the credential strategy to adopt: CONNECTION_STRING, TOKEN_CREDENTIAL with the tokenCredential option, or AZURE_IDENTITY with a DefaultAzureCredential: the tokenCredential option when it is set, otherwise a new one. When not set, it is TOKEN_CREDENTIAL (or AZURE_IDENTITY for a DefaultAzureCredential) when tokenCredential is set, else CONNECTION_STRING. Enum values:
| CONNECTION_STRING | CredentialType | |
The fully qualified namespace of the Service Bus, such as mynamespace.servicebus.windows.net, to connect to with credentialType TOKEN_CREDENTIAL or AZURE_IDENTITY. Not used to connect with CONNECTION_STRING, where the connection string holds the namespace. | String | ||
Autowired The com.azure.core.credential.TokenCredential to authenticate with Microsoft Entra ID, for credentialType TOKEN_CREDENTIAL or AZURE_IDENTITY. A DefaultAzureCredential built with a managed identity client id or a tenant id is used as it is. | TokenCredential |
Endpoint Options
The Azure ServiceBus endpoint is configured using URI syntax:
azure-servicebus:topicOrQueueName
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The AmqpRetryOptions of the Service Bus clients: the retry mode, the maximum number of retries, the delay and maximum delay between retries, and the try timeout of an operation. When not set, the SDK retries 3 times with an exponential delay from 0.8 seconds up to 1 minute, and a try timeout of 60 seconds. | AmqpRetryOptions | ||
The AmqpTransportType of the connection to Service Bus: AMQP (AMQP over TLS on port 5671) or AMQP_WEB_SOCKETS (AMQP over web sockets on port 443, needed with proxyOptions or when port 5671 is blocked). Enum values:
| AMQP | AmqpTransportType | |
The ClientOptions of the Service Bus clients: the application id that is sent in the user agent, and the tracing and metrics options. An AmqpClientOptions also sets the identifier of the clients. | ClientOptions | ||
The HeaderFilterStrategy that decides which Camel message headers the producer sends as application properties of the message, and which application properties of a received message the consumer sets as headers. The default leaves out names that start with Camel or camel, and the producer sends only headers with a value of type String, Boolean, Byte, Short, Integer, Long, Float, Double, Character, Date or UUID. | HeaderFilterStrategy | ||
The ProxyOptions of the proxy to connect to Service Bus through, for the producer and the consumer. A proxy needs amqpTransportType AMQP_WEB_SOCKETS: with AMQP the client fails to build. When not set, the SDK uses a proxy from its environment configuration, if one is configured. | ProxyOptions | ||
Required Whether topicOrQueueName is the name of a queue or of a topic. The consumer of a topic receives from the subscription set in subscriptionName. Enum values:
| queue | ServiceBusType | |
Dead-letters the message of a failed exchange instead of abandoning it, with the exception as the dead-letter reason and its stack trace as the error description. The message goes to the dead-letter queue of the queue or subscription it was received from. Applies only in PEEK_LOCK receive mode, and not when reading a sub-queue (subQueue), where the message is abandoned. | false | boolean | |
How long the consumer keeps renewing the lock of a message while its exchange is in progress, in PEEK_LOCK receive mode, as a duration (such as 10m or PT10M) or in milliseconds. The lock is renewed shortly before it expires, until the exchange completes or this time has passed. 0 turns renewal off, so Service Bus delivers a message again when its exchange takes longer than the lock duration of the queue or subscription. With sessionEnabled, it is how long the SDK keeps renewing the session lock instead. Not used in RECEIVE_AND_DELETE receive mode. | 300000 | long | |
The maximum number of messages that the processor client hands to the route at the same time (concurrent calls of its message callback), at least 1. With sessionEnabled it is per session, so up to maxConcurrentSessions times maxConcurrentCalls messages. A call ends when the route continues asynchronously, so an asynchronous route can have more exchanges in flight. | 1 | int | |
The maximum number of sessions the consumer processes at the same time, each with up to maxConcurrentCalls messages at the same time. Only used when sessionEnabled is true. | 1 | int | |
The number of messages the processor client fetches from Service Bus ahead of the ones it is processing. 0 (the default) turns prefetch off: the consumer asks for a message only when a call is free to process it. In PEEK_LOCK receive mode, the lock of a prefetched message already runs while the message waits in the buffer. | int | ||
Autowired A ServiceBusProcessorClient to use instead of one that the consumer builds. The consumer only starts it, and stops it (without closing it) when the consumer stops: the client hands its messages to the processMessage callback it was built with, not to the route, and the consumer options (such as serviceBusReceiveMode, maxAutoLockRenewDuration or enableDeadLettering) do not apply to it. | ServiceBusProcessorClient | ||
How the consumer receives messages. PEEK_LOCK: Service Bus locks each message, and the consumer completes it when its exchange succeeds, or abandons it (dead-letters it with enableDeadLettering) when the exchange fails, so that Service Bus delivers it again, up to the maximum delivery count of the queue or subscription. RECEIVE_AND_DELETE: Service Bus deletes each message when it delivers it, so the message of a failed exchange is lost. Enum values:
| PEEK_LOCK | ServiceBusReceiveMode | |
Whether the consumer receives from a session-enabled queue or subscription, with a session processor client: it locks a session and receives the messages of that session in order, up to maxConcurrentSessions sessions at the same time. Needed to receive from a session-enabled queue or subscription. | false | boolean | |
How long a session-enabled consumer waits for the next message of a session before it closes the session and tries to lock another one, as a duration (such as 30s or PT30S) or in milliseconds. 0 or less (the default is -1) keeps the default of the Service Bus SDK. Only used when sessionEnabled is true. An idle session holds one of the maxConcurrentSessions slots for this long, so use a value that just covers the slowest asynchronous route. | -1 | long | |
The sub-queue of the queue or subscription to receive from: DEAD_LETTER_QUEUE (the dead-letter queue) or TRANSFER_DEAD_LETTER_QUEUE (the transfer dead-letter queue). When not set, or NONE, the consumer receives from the queue or subscription itself. Enum values:
| SubQueue | ||
Sets the name of the subscription in the topic to listen to. topicOrQueueName and serviceBusType=topic must also be set. This property is required if serviceBusType=topic and the consumer is in use. | String | ||
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 | ||
Whether the producer sends the body as bytes: a stream or a file (File or Path) as read, and any other body converted to byte[]. When false, the body is converted to a String. A BinaryData body is sent as it is either way. Applies to each element of a List body too. | false | boolean | |
The operation of the producer: sendMessages sends the message (or each element of a List body) at once, scheduleMessages schedules it to be enqueued at scheduledEnqueueTime. The CamelAzureServiceBusProducerOperation header overrides it. Enum values:
| sendMessages | ServiceBusProducerOperationDefinition | |
Sets OffsetDateTime at which the message should appear in the Service Bus queue or topic. Used only by the scheduleMessages producer operation; sendMessages sends the message at once. In an endpoint URI or a property use an ISO-8601 date-time with an offset, such as 2026-11-18T22:00:00Z or 2026-11-18T23:00:00+01:00. | OffsetDateTime | ||
Autowired A ServiceBusSenderClient to use instead of one that the producer builds. It sends to the queue or topic it was built for, so the connection options (such as connectionString, serviceBusType and topicOrQueueName) do not apply to it, and the producer does not close it. | ServiceBusSenderClient | ||
The ServiceBusTransactionContext (the id of a transaction created with createTransaction() of a Service Bus client) to send or schedule the messages in. The producer does not commit or roll back the transaction. The CamelAzureServiceBusServiceBusTransactionContext header overrides it. | ServiceBusTransactionContext | ||
The session id that the producer sets on every message it sends, as a session-enabled queue or topic needs one. The CamelAzureServiceBusSessionId header is not used. | String | ||
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 | |
Sets the connection string for a Service Bus namespace or a specific Service Bus resource. Connection strings commonly contain characters with a special meaning in URIs (the SharedAccessKey is a Base64 value that may contain plus, slash or equals characters): when configuring the connection string directly in an endpoint URI, wrap the value with RAW() so it is not URI-decoded. | String | ||
Determines the credential strategy to adopt: CONNECTION_STRING, TOKEN_CREDENTIAL with the tokenCredential option, or AZURE_IDENTITY with a DefaultAzureCredential: the tokenCredential option when it is set, otherwise a new one. When not set, it is TOKEN_CREDENTIAL (or AZURE_IDENTITY for a DefaultAzureCredential) when tokenCredential is set, else CONNECTION_STRING. Enum values:
| CONNECTION_STRING | CredentialType | |
The fully qualified namespace of the Service Bus, such as mynamespace.servicebus.windows.net, to connect to with credentialType TOKEN_CREDENTIAL or AZURE_IDENTITY. Not used to connect with CONNECTION_STRING, where the connection string holds the namespace. | String | ||
Autowired The com.azure.core.credential.TokenCredential to authenticate with Microsoft Entra ID, for credentialType TOKEN_CREDENTIAL or AZURE_IDENTITY. A DefaultAzureCredential built with a managed identity client id or a tenant id is used as it is. | TokenCredential |
Message Headers
The Azure ServiceBus component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAzureServiceBusApplicationProperties (common) Constant: | (producer) A map of application properties to set on the message. The headers that headerFilterStrategy lets through are added to it, replacing an entry of the same name. A Content-Type entry also sets the content type of the message. (consumer) The application properties of the received message. | Map | |
CamelAzureServiceBusContentType (consumer) Constant: | Gets the content type of the message. | String | |
CamelAzureServiceBusDeadLetterErrorDescription (consumer) Constant: | Gets the description for a message that has been dead-lettered. | String | |
CamelAzureServiceBusDeadLetterReason (consumer) Constant: | Gets the reason a message was dead-lettered. | String | |
CamelAzureServiceBusDeadLetterSource (consumer) Constant: | Gets the name of the queue or subscription that this message was enqueued on, before it was dead-lettered. | String | |
CamelAzureServiceBusDeliveryCount (consumer) Constant: | Gets the number of the times this message was delivered to clients. | long | |
CamelAzureServiceBusEnqueuedSequenceNumber (consumer) Constant: | Gets the enqueued sequence number assigned to a message by Service Bus. | long | |
CamelAzureServiceBusEnqueuedTime (consumer) Constant: | Gets the datetime at which this message was enqueued in Azure Service Bus. | OffsetDateTime | |
CamelAzureServiceBusExpiresAt (consumer) Constant: | Gets the datetime at which this message will expire. | OffsetDateTime | |
CamelAzureServiceBusLockToken (consumer) Constant: | Gets the lock token for the current message. | String | |
CamelAzureServiceBusLockedUntil (consumer) Constant: | Gets the datetime at which the lock of this message expires. | OffsetDateTime | |
CamelAzureServiceBusMessageId (consumer) Constant: | Gets the identifier for the message. | String | |
CamelAzureServiceBusPartitionKey (consumer) Constant: | The partition key of the received message, which a partitioned queue or topic uses to choose the partition. | String | |
CamelAzureServiceBusTopicOrQueueName (consumer) Constant: | The name of the queue or topic the message was received from. | String | |
CamelAzureServiceBusRawAmqpMessage (consumer) Constant: | The received message as an AmqpAnnotatedMessage, with all the sections of the AMQP message. | AmqpAnnotatedMessage | |
CamelAzureServiceBusReplyTo (consumer) Constant: | Gets the address of an entity to send replies to. | String | |
CamelAzureServiceBusReplyToSessionId (consumer) Constant: | The session id augmenting the ReplyTo address, which a reply should be sent with. | String | |
CamelAzureServiceBusSequenceNumber (consumer) Constant: | Gets the unique number assigned to a message by Service Bus. | long | |
CamelAzureServiceBusSessionId (consumer) Constant: | Gets the session id of the message. | String | |
CamelAzureServiceBusSubject (consumer) Constant: | Gets the subject for the message. | String | |
CamelAzureServiceBusTimeToLive (consumer) Constant: | Gets the duration before this message expires. | Duration | |
CamelAzureServiceBusTo (consumer) Constant: | The to address of the received message, which the broker does not use (it is meant for routing scenarios such as auto-forward chaining). | String | |
CamelAzureServiceBusScheduledEnqueueTime (common) Constant: | (producer) Overrides the OffsetDateTime at which the message should appear in the Service Bus queue or topic. Used only by the scheduleMessages operation. (consumer) Gets the scheduled enqueue time of this message. | OffsetDateTime | |
CamelAzureServiceBusServiceBusTransactionContext (producer) Constant: | The ServiceBusTransactionContext to send or schedule the messages in, overriding the serviceBusTransactionContext option. | ServiceBusTransactionContext | |
CamelAzureServiceBusProducerOperation (producer) Constant: | The producer operation to invoke, sendMessages or scheduleMessages, overriding the producerOperation option. Enum values:
| ServiceBusProducerOperationDefinition | |
CamelAzureServiceBusCorrelationId (common) Constant: | (producer) The correlation id to set on the message, or on every message of a List body. (consumer) The correlation id of the received message. | String |
Message Body
The message body at each side of the Azure ServiceBus 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 Service Bus message as an Azure BinaryData, which converts to a String, bytes or a stream. |
Producer input |
| Sent as text by default: bytes, a stream or a file are read as text, so binary content needs binary=true. A BinaryData, as the consumer gives it, is sent as it is, and a Map or a POJO is sent as its toString(): marshal it first. A List is sent as one message per element. |
Producer output |
| Unchanged, also after scheduleMessages. |
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 Azure ServiceBus 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: FakeServiceBus: a queue in peek-lock mode (lock duration, delivery count, dead-letter queue) behind the processor and receiver clients of ServiceBusClientFactory 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
Authentication Information
There are three different Credential Types: AZURE_IDENTITY, TOKEN_CREDENTIAL and CONNECTION_STRING. To use this component, you have three options to provide the required Azure authentication information:
CONNECTION_STRING:
-
Provide
connectionStringstring it is the simplest option to get started.
| The See Configuring parameter values using raw values for more details. |
TOKEN_CREDENTIAL:
-
Provide an implementation of
com.azure.core.credential.TokenCredentialinto the Camel’s Registry, e.g., using thecom.azure.identity.DefaultAzureCredentialBuilder().build();API. See the documentation here about Azure-AD authentication.
AZURE_IDENTITY:
-
This will use
com.azure.identity.DefaultAzureCredentialBuilder().build();instance. This will follow the Default Azure Credential Chain. See the documentation here about Azure-AD authentication.
Custom Client Instance
It is possible to provide a custom client instance on either the consumer or producer endpoints. com.azure.messaging.servicebus.ServiceBusSenderClient for sending messages and com.azure.messaging.servicebus.ServiceBusProcessorClient to receive messages. A custom ServiceBusProcessorClient hands its messages to the processMessage callback it was built with, not to the route: the consumer only starts and stops it. When clients are bound to the Camel registry, they will be autowired into the Service Bus component.
Message Body
In the producer, this component accepts a message body of String, byte[] and BinaryData types. Or List<String>, List<byte[]> and List<BinaryData> to send batch messages.
In the consumer, the returned message body will be of type com.azure.core.util.BinaryData, which converts to String, byte[] and InputStream.
Azure ServiceBus Producer operations
| Operation | Description |
|---|---|
| Sends a set of messages to a Service Bus queue or topic using a batched approach. |
| Sends a scheduled message to the Azure Service Bus queue or topic. A scheduled message is enqueued and made available to receivers only at the scheduled time. |
Examples
-
sendMessages
from("direct:start")
.process(exchange -> {
final List<Object> inputBatch = new LinkedList<>();
inputBatch.add("test batch 1");
inputBatch.add("test batch 2");
inputBatch.add("test batch 3");
inputBatch.add(123456);
exchange.getIn().setBody(inputBatch);
})
.to("azure-servicebus:test//?connectionString=test")
.to("mock:result"); from("direct:start")
.process(exchange -> {
final List<Object> inputBatch = new LinkedList<>();
inputBatch.add("test batch 1");
inputBatch.add("test batch 2");
inputBatch.add("test batch 3");
inputBatch.add(123456);
exchange.getIn().setBody(inputBatch);
})
.to("azure-servicebus:test//?connectionString=test&sessionId=123")
.to("mock:result"); -
scheduleMessages
from("direct:start")
.process(exchange -> {
final List<Object> inputBatch = new LinkedList<>();
inputBatch.add("test batch 1");
inputBatch.add("test batch 2");
inputBatch.add("test batch 3");
inputBatch.add(123456);
exchange.getIn().setHeader(ServiceBusConstants.SCHEDULED_ENQUEUE_TIME, OffsetDateTime.now());
exchange.getIn().setBody(inputBatch);
})
.to("azure-servicebus:test//?connectionString=test&producerOperation=scheduleMessages")
.to("mock:result"); The time can also be set with the scheduledEnqueueTime option, or as a string in the header, as an ISO-8601 date-time with an offset, such as 2026-11-18T22:00:00Z or 2026-11-18T23:00:00+01:00. The option and the header are used only by scheduleMessages: sendMessages sends the message at once.
from("direct:start")
.to("azure-servicebus:test?connectionString=test&producerOperation=scheduleMessages&scheduledEnqueueTime=2026-11-18T23:00:00+01:00"); -
receiveMessages
-
Java
-
XML
-
YAML
from("azure-servicebus:test//?connectionString=test")
.log("${body}")
.to("mock:result"); <route>
<from uri="azure-servicebus:test//?connectionString=test"/>
<log message="${body}"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: azure-servicebus:test//
parameters:
connectionString: test
steps:
- log:
message: "${body}"
- to:
uri: mock:result -
Java
-
XML
-
YAML
from("azure-servicebus:test//?connectionString=test&sessionEnabled=true")
.log("${body}")
.to("mock:result"); <route>
<from uri="azure-servicebus:test//?connectionString=test&sessionEnabled=true"/>
<log message="${body}"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: azure-servicebus:test//
parameters:
connectionString: test
sessionEnabled: true
steps:
- log:
message: "${body}"
- to:
uri: mock:result Session idle timeout for async routes
When sessionEnabled=true and routes process messages asynchronously (the processMessage callback returns before the exchange is settled), the session processor’s idle timer may expire before the async route finishes, causing the session to close and the message to be redelivered.
Use sessionIdleTimeout to extend the session idle window to cover the slowest expected processing time:
from("azure-servicebus:test//?connectionString=test&sessionEnabled=true&sessionIdleTimeout=120000")
.log("${body}")
.to("mock:result"); A longer timeout keeps an idle session — one of the maxConcurrentSessions slots — occupied until the timer fires, so choose the smallest value that covers the longest expected processing time.