= Azure ServiceBus Component
:doctitle: Azure ServiceBus
:shortname: azure-servicebus
:artifactid: camel-azure-servicebus
:description: Send and receive messages to/from Azure Event Bus.
:since: 3.12
:supportlevel: Stable
:component-header: Both producer and consumer are supported
//Manually maintained attributes
:group: Azure
:camel-spring-boot-name: azure-servicebus

*Since Camel {since}*

*{component-header}*

The azure-servicebus component that integrates https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview[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 a valid Windows Azure Storage account. More information is available at
https://docs.microsoft.com/azure/[Azure Documentation Portal].

[source,xml]
------------------------------------------------------------
<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>
------------------------------------------------------------


// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END


== Async Consumer and Producer

This component implements the async Consumer and producer.

This allows camel route to consume and produce events asynchronously without blocking any threads.

== Usage

// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: END

=== Message Body
In the producer, this component accepts message body of `String` type or `List<String>` to send batch messages.

In the consumer, the returned message body will be of type `String.


=== Azure ServiceBus Producer operations
[width="100%",cols="10%,90%",options="header",]
|===
|Operation |Description
|`sendMessages`  | Sends a set of messages to a Service Bus queue or topic using a batched approach.
|`scheduleMessages`  | Sends a scheduled message to the Azure Service Bus entity this sender is connected to. A scheduled message is enqueued and made available to receivers only at the scheduled enqueue time.
|===


=== Azure ServiceBus Consumer operations
[width="100%",cols="10%,90%",options="header",]
|===
|Operation |Description
|`receiveMessages`  | Receives an <b>infinite</b> stream of messages from the Service Bus entity.
|`peekMessages`  | Reads the next batch of active messages without changing the state of the receiver or the message source.
|===


==== Examples
- `sendMessages`

[source,java]
--------------------------------------------------------------------------------
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");
--------------------------------------------------------------------------------


- `scheduleMessages`

[source,java]
--------------------------------------------------------------------------------
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");
--------------------------------------------------------------------------------

- `receiveMessages`

[source,java]
--------------------------------------------------------------------------------
from("azure-servicebus:test//?connectionString=test")
  .log("${body}")
  .to("mock:result");
--------------------------------------------------------------------------------

- `peekMessages`

[source,java]
--------------------------------------------------------------------------------
from("azure-servicebus:test//?connectionString=test&consumerOperation=peekMessages&peekNumMaxMessages=3")
  .log("${body}")
  .to("mock:result");
--------------------------------------------------------------------------------



include::spring-boot:partial$starter.adoc[]
