### Transaction Management Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient APIs for managing Service Bus transactions, including starting and rolling back. ```APIDOC ## createTransaction ### Description Starts a new transaction on Service Bus. The ServiceBusTransactionContext should be passed along to all operations that need to be in this transaction. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/createTransaction ### Response #### Success Response (200) - **ServiceBusTransactionContext** (object) - A new ServiceBusTransactionContext. ### Response Example { "example": "ServiceBusTransactionContext" } ## rollbackTransaction ### Description Rollbacks the transaction given and all operations associated with it. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/rollbackTransaction ### Parameters #### Request Body - **transactionContext** (ServiceBusTransactionContext) - Required - The transaction to rollback. ### Request Example { "transactionContext": { "example": "ServiceBusTransactionContext" } } ### Response #### Success Response (200) - **void** - Indicates successful rollback. ### Response Example { "example": "Success" } ``` -------------------------------- ### Create Service Bus Transaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Starts a new transaction on Service Bus. This allows for atomic operations on Service Bus entities. ```java public ServiceBusTransactionContext createTransaction() ``` -------------------------------- ### Get Service Bus Sender Client Information Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Retrieves information about the Service Bus sender client, including its entity path, fully qualified namespace, and unique identifier. ```java public String getEntityPath() ``` ```java public String getFullyQualifiedNamespace() ``` ```java public String getIdentifier() ``` -------------------------------- ### Commit Service Bus Transaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Commits a transaction that was previously started and is identified by the provided ServiceBusTransactionContext. ```java public void commitTransaction(ServiceBusTransactionContext transactionContext) ``` -------------------------------- ### createMessageBatch Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Creates a batch for sending messages. ```APIDOC ## createMessageBatch ### Description Creates a ServiceBusMessageBatch that can fit as many messages as the transport allows. ### Parameters - **options** (CreateMessageBatchOptions) - Optional - A set of options used to configure the ServiceBusMessageBatch. ### Response - **ServiceBusMessageBatch** - A new ServiceBusMessageBatch configured with the given options. ``` -------------------------------- ### Create ServiceBusSenderClient Instance Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Instantiate a ServiceBusSenderClient using DefaultAzureCredential and a ServiceBusClientBuilder. This client is used for sending messages to a specified queue. ```Java TokenCredential credential = new DefaultAzureCredentialBuilder().build(); // 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net" ServiceBusSenderClient sender = new ServiceBusClientBuilder() .credential(fullyQualifiedNamespace, credential) .sender() .queueName(queueName) .buildClient(); sender.sendMessage(new ServiceBusMessage("Foo bar")); ``` -------------------------------- ### Entity Information Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient APIs for retrieving information about the Service Bus entity. ```APIDOC ## getEntityPath ### Description Gets the name of the Service Bus resource. ### Method GET ### Endpoint /websites/learn_microsoft_java_api/entityPath ### Response #### Success Response (200) - **String** (string) - The name of the Service Bus resource. ### Response Example { "example": "my-service-bus-entity" } ## getFullyQualifiedNamespace ### Description Gets the fully qualified namespace. ### Method GET ### Endpoint /websites/learn_microsoft_java_api/fullyQualifiedNamespace ### Response #### Success Response (200) - **String** (string) - The fully qualified namespace. ### Response Example { "example": "my-namespace.servicebus.windows.net" } ## getIdentifier ### Description Gets the identifier of the instance of ServiceBusSenderClient. ### Method GET ### Endpoint /websites/learn_microsoft_java_api/identifier ### Response #### Success Response (200) - **String** (string) - The identifier that can identify the instance of ServiceBusSenderClient. ### Response Example { "example": "sender-client-123" } ``` -------------------------------- ### ServiceBusSenderClient Operations Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Methods for initializing the sender client and performing message transmission operations including single messages, batches, and session-based sending. ```APIDOC ## ServiceBusSenderClient Operations ### Description The ServiceBusSenderClient provides methods to send messages to Azure Service Bus queues or topics. It supports creating message batches, sending individual messages, and handling session-enabled queues. ### Methods - **sendMessage(ServiceBusMessage message)**: Sends a single message to the configured queue or topic. - **sendMessages(ServiceBusMessageBatch batch)**: Sends a batch of messages to the configured queue or topic. - **createMessageBatch()**: Creates a new ServiceBusMessageBatch for grouping messages. - **createMessageBatch(CreateMessageBatchOptions options)**: Creates a new ServiceBusMessageBatch with specific size constraints. - **close()**: Closes the client and releases underlying resources. ### Request Example ```java // Initialize client ServiceBusSenderClient sender = new ServiceBusClientBuilder() .credential(fullyQualifiedNamespace, credential) .sender() .queueName(queueName) .buildClient(); // Send single message sender.sendMessage(new ServiceBusMessage("Foo bar")); // Send batch ServiceBusMessageBatch batch = sender.createMessageBatch(); batch.tryAddMessage(new ServiceBusMessage("test-1")); sender.sendMessages(batch); ``` ``` -------------------------------- ### Send Message to Session-Enabled Queue Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Demonstrates sending a message to a Service Bus session-enabled queue by setting the sessionId property. This directs the message to a specific session identified by the provided ID. ```Java // 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net" ServiceBusSenderClient sender = new ServiceBusClientBuilder() .credential(fullyQualifiedNamespace, new DefaultAzureCredentialBuilder().build()) .sender() .queueName(sessionEnabledQueueName) .buildClient(); // Setting sessionId publishes that message to a specific session, in this case, "greeting". ``` -------------------------------- ### Send Multiple Messages in Batches Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Send a list of ServiceBusMessage objects by creating and populating message batches. Handles full batches by sending them and creating new ones. Ensure to send the final batch if it contains messages. ```Java TokenCredential credential = new DefaultAzureCredentialBuilder().build(); // 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net" ServiceBusSenderClient sender = new ServiceBusClientBuilder() .credential(fullyQualifiedNamespace, credential) .sender() .queueName(queueName) .buildClient(); List messages = Arrays.asList( new ServiceBusMessage("test-1"), new ServiceBusMessage("test-2")); // Creating a batch without options set. ServiceBusMessageBatch batch = sender.createMessageBatch(); for (ServiceBusMessage message : messages) { if (batch.tryAddMessage(message)) { continue; } // The batch is full. Send the current batch and create a new one. sender.sendMessages(batch); batch = sender.createMessageBatch(); // Add the message we couldn't before. if (!batch.tryAddMessage(message)) { throw new IllegalArgumentException("Message is too large for an empty batch."); } } // Send the final batch if there are any messages in it. if (batch.getCount() > 0) { sender.sendMessages(batch); } // Continue using the sender and finally, dispose of the sender. // Clients should be long-lived objects as they require resources // and time to establish a connection to the service. sender.close(); ``` -------------------------------- ### sendMessages (Batch) Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a pre-created message batch to the connected Service Bus entity. ```APIDOC ## sendMessages(ServiceBusMessageBatch batch) ### Description Sends a message batch to the Azure Service Bus entity this sender is connected to. ### Parameters - **batch** (ServiceBusMessageBatch) - Required - A batch of messages which allows client to send maximum allowed size for a batch of messages. ## sendMessages(ServiceBusMessageBatch batch, ServiceBusTransactionContext transactionContext) ### Description Sends a message batch to the Azure Service Bus entity this sender is connected to with an optional transaction context. ### Parameters - **batch** (ServiceBusMessageBatch) - Required - A batch of messages which allows client to send maximum allowed size for a batch of messages. - **transactionContext** (ServiceBusTransactionContext) - Optional - To be set on message before sending to Service Bus. ``` -------------------------------- ### Create Service Bus Message Batch Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Creates a ServiceBusMessageBatch. This batch can hold as many messages as the transport allows. An optional set of options can be provided to configure the batch. ```java public ServiceBusMessageBatch createMessageBatch() ``` ```java public ServiceBusMessageBatch createMessageBatch(CreateMessageBatchOptions options) ``` -------------------------------- ### Message Sending Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient APIs for sending single messages or batches of messages. ```APIDOC ## sendMessage (single) ### Description Sends a message to a Service Bus queue or topic. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/sendMessage ### Parameters #### Request Body - **message** (ServiceBusMessage) - Required - Message to be sent to Service Bus queue or topic. ### Request Example { "message": { "example": "ServiceBusMessage" } } ### Response #### Success Response (200) - **void** - Indicates successful sending. ### Response Example { "example": "Success" } ## sendMessage (with transaction) ### Description Sends a message to a Service Bus queue or topic. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/sendMessage ### Parameters #### Request Body - **message** (ServiceBusMessage) - Required - Message to be sent to Service Bus queue or topic. - **transactionContext** (ServiceBusTransactionContext) - Required - to be set on message before sending to Service Bus. ### Request Example { "message": { "example": "ServiceBusMessage" }, "transactionContext": { "example": "ServiceBusTransactionContext" } } ### Response #### Success Response (200) - **void** - Indicates successful sending. ### Response Example { "example": "Success" } ## sendMessages (batch) ### Description Sends a set of ServiceBusMessage to a Service Bus queue or topic using a batched approach. If the size of messages exceed the maximum size of a single batch, an exception will be triggered and the send will fail. By default, the message size is the max amount allowed on the link. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/sendMessages ### Parameters #### Request Body - **messages** (Iterable) - Required - Messages to be sent to Service Bus queue or topic. ### Request Example { "messages": [ { "example": "ServiceBusMessage" } ] } ### Response #### Success Response (200) - **void** - Indicates successful sending. ### Response Example { "example": "Success" } ``` -------------------------------- ### Message Scheduling Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient APIs for scheduling single messages or batches of messages for future delivery. ```APIDOC ## scheduleMessage (single) ### Description 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. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/scheduleMessage ### Parameters #### Request Body - **message** (ServiceBusMessage) - Required - Message to be sent to the Service Bus Queue or Topic. - **scheduledEnqueueTime** (OffsetDateTime) - Required - Datetime at which the message should appear in the Service Bus queue or topic. ### Request Example { "message": { "example": "ServiceBusMessage" }, "scheduledEnqueueTime": "2023-10-27T10:00:00Z" } ### Response #### Success Response (200) - **Long** (long) - The sequence number of the scheduled message which can be used to cancel the scheduling of the message. ### Response Example { "example": 1234567890 } ## scheduleMessage (with transaction) ### Description 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. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/scheduleMessage ### Parameters #### Request Body - **message** (ServiceBusMessage) - Required - Message to be sent to the Service Bus Queue or Topic. - **scheduledEnqueueTime** (OffsetDateTime) - Required - Datetime at which the message should appear in the Service Bus queue or topic. - **transactionContext** (ServiceBusTransactionContext) - Required - to be set on message before sending to Service Bus. ### Request Example { "message": { "example": "ServiceBusMessage" }, "scheduledEnqueueTime": "2023-10-27T10:00:00Z", "transactionContext": { "example": "ServiceBusTransactionContext" } } ### Response #### Success Response (200) - **Long** (long) - The sequence number of the scheduled message which can be used to cancel the scheduling of the message. ### Response Example { "example": 1234567890 } ## scheduleMessages (batch) ### Description Sends a batch of scheduled messages 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. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/scheduleMessages ### Parameters #### Request Body - **messages** (Iterable) - Required - Messages to be sent to the Service Bus queue or topic. - **scheduledEnqueueTime** (OffsetDateTime) - Required - Instant at which the message should appear in the Service Bus queue or topic. ### Request Example { "messages": [ { "example": "ServiceBusMessage" } ], "scheduledEnqueueTime": "2023-10-27T10:00:00Z" } ### Response #### Success Response (200) - **Iterable** (Iterable) - Sequence numbers of the scheduled messages which can be used to cancel the messages. ### Response Example { "example": [1234567890, 1234567891] } ## scheduleMessages (batch with transaction) ### Description Sends a batch of scheduled messages 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. ### Method POST ### Endpoint /websites/learn_microsoft_java_api/scheduleMessages ### Parameters #### Request Body - **messages** (Iterable) - Required - Messages to be sent to the Service Bus Queue or Topic. - **scheduledEnqueueTime** (OffsetDateTime) - Required - Instant at which the message should appear in the Service Bus queue or topic. - **transactionContext** (ServiceBusTransactionContext) - Required - Transaction to associate with the operation. ### Request Example { "messages": [ { "example": "ServiceBusMessage" } ], "scheduledEnqueueTime": "2023-10-27T10:00:00Z", "transactionContext": { "example": "ServiceBusTransactionContext" } } ### Response #### Success Response (200) - **Iterable** (Iterable) - Sequence numbers of the scheduled messages which can be used to cancel the messages. ### Response Example { "example": [1234567890, 1234567891] } ``` -------------------------------- ### Send Messages with Size-Limited Batches Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Create and send messages using ServiceBusMessageBatch instances with a specified maximum size in bytes. This is useful for controlling the size of individual batches sent to the service. ```Java List telemetryMessages = Arrays.asList(firstMessage, secondMessage, thirdMessage); // Setting `setMaximumSizeInBytes` when creating a batch, limits the size of that batch. // In this case, all the batches created with these options are limited to 256 bytes. CreateMessageBatchOptions options = new CreateMessageBatchOptions() .setMaximumSizeInBytes(256); ServiceBusMessageBatch currentBatch = sender.createMessageBatch(options); // For each telemetry message, we try to add it to the current batch. // When the batch is full, send it then create another batch to add more mesages to. for (ServiceBusMessage message : telemetryMessages) { if (!currentBatch.tryAddMessage(message)) { sender.sendMessages(currentBatch); currentBatch = sender.createMessageBatch(options); // Add the message we couldn't before. if (!currentBatch.tryAddMessage(message)) { throw new IllegalArgumentException("Message is too large for an empty batch."); } } } // Send the final batch if there are any messages in it. if (currentBatch.getCount() > 0) { sender.sendMessages(currentBatch); } // Continue using the sender and finally, dispose of the sender. // Clients should be long-lived objects as they require resources // and time to establish a connection to the service. sender.close(); ``` -------------------------------- ### close Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Disposes of the ServiceBusSenderClient. ```APIDOC ## close ### Description Disposes of the ServiceBusSenderClient. If the client has a dedicated connection, the underlying connection is also closed. ``` -------------------------------- ### Send Message Batch Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a pre-formed batch of messages to the Azure Service Bus entity. This is useful for sending the maximum allowed size of messages in a single operation. ```java public void sendMessages(ServiceBusMessageBatch batch) ``` -------------------------------- ### sendMessages (Iterable) Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a collection of messages to a Service Bus queue or topic using a batched approach. ```APIDOC ## sendMessages(Iterable messages, ServiceBusTransactionContext transactionContext) ### Description Sends a set of ServiceBusMessage to a Service Bus queue or topic using a batched approach. If the size of messages exceed the maximum size of a single batch, an exception will be triggered. ### Parameters - **messages** (Iterable) - Required - Messages to be sent to Service Bus queue or topic. - **transactionContext** (ServiceBusTransactionContext) - Optional - To be set on message before sending to Service Bus. ``` -------------------------------- ### Send Batched Messages with Transaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a collection of Service Bus messages to a queue or topic using a batched approach within a transaction. This method fails if the total message size exceeds the maximum allowed batch size. ```java public void sendMessages(Iterable messages, ServiceBusTransactionContext transactionContext) ``` -------------------------------- ### Send Message Batch with Transaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a pre-formed batch of messages to the Azure Service Bus entity within a transaction. This method allows for sending the maximum allowed size of messages in a single transactional operation. ```java public void sendMessages(ServiceBusMessageBatch batch, ServiceBusTransactionContext transactionContext) ``` -------------------------------- ### Send Batched Service Bus Messages Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a set of ServiceBusMessage objects to a Service Bus queue or topic using a batched approach for efficiency. Transactions can optionally be included. ```java public void sendMessages(Iterable messages) ``` ```java public void sendMessages(Iterable messages, ServiceBusTransactionContext transactionContext) ``` ```java public void sendMessages(ServiceBusMessageBatch batch) ``` ```java public void sendMessages(ServiceBusMessageBatch batch, ServiceBusTransactionContext transactionContext) ``` -------------------------------- ### Send Service Bus Message with Transaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a message to a Service Bus queue or topic within the context of an existing transaction. ```java public void sendMessage(ServiceBusMessage message, ServiceBusTransactionContext transactionContext) ``` -------------------------------- ### Send a Service Bus Message Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Sends a single message to a Service Bus queue or topic. Ensure the sender is disposed of after use. ```java ServiceBusMessage message = new ServiceBusMessage("Hello world") .setSessionId("greetings"); sender.sendMessage(message); // Dispose of the sender. sender.close(); ``` -------------------------------- ### commitTransaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Commits a transaction. ```APIDOC ## commitTransaction ### Description Commits the transaction given ServiceBusTransactionContext. ### Parameters - **transactionContext** (ServiceBusTransactionContext) - Required - The transaction context to be committed. ``` -------------------------------- ### Schedule Service Bus Messages Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Schedules one or more messages to be sent to a Service Bus entity at a specified time. Transactions can optionally be included. ```java public Long scheduleMessage(ServiceBusMessage message, OffsetDateTime scheduledEnqueueTime) ``` ```java public Long scheduleMessage(ServiceBusMessage message, OffsetDateTime scheduledEnqueueTime, ServiceBusTransactionContext transactionContext) ``` ```java public Iterable scheduleMessages(Iterable messages, OffsetDateTime scheduledEnqueueTime) ``` ```java public Iterable scheduleMessages(Iterable messages, OffsetDateTime scheduledEnqueueTime, ServiceBusTransactionContext transactionContext) ``` -------------------------------- ### cancelScheduledMessages Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Cancels the enqueuing of multiple scheduled messages. ```APIDOC ## cancelScheduledMessages ### Description Cancels the enqueuing of scheduled messages, if they are not already enqueued. ### Parameters - **sequenceNumbers** (Iterable) - Required - The sequence numbers of messages to cancel. ``` -------------------------------- ### cancelScheduledMessage Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Cancels the enqueuing of a scheduled message. ```APIDOC ## cancelScheduledMessage ### Description Cancels the enqueuing of a scheduled message, if they are not already enqueued. ### Parameters - **sequenceNumber** (long) - Required - The sequence number of the message to cancel. ``` -------------------------------- ### Close Service Bus Sender Client Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Disposes of the ServiceBusSenderClient. If the client was created with a dedicated connection, that connection will also be closed. ```java public void close() ``` -------------------------------- ### Cancel Scheduled Service Bus Messages Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Cancels the enqueuing of scheduled messages using their sequence numbers. This operation is effective only if the messages have not yet been enqueued. ```java public void cancelScheduledMessage(long sequenceNumber) ``` ```java public void cancelScheduledMessages(Iterable sequenceNumbers) ``` -------------------------------- ### Rollback Service Bus Transaction Source: https://learn.microsoft.com/java/api/com.azure.messaging.servicebus.servicebussenderclient Rolls back a transaction identified by the provided ServiceBusTransactionContext. All operations associated with this transaction will be undone. ```java public void rollbackTransaction(ServiceBusTransactionContext transactionContext) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.