Class ServiceBusTemplate
java.lang.Object
com.azure.spring.messaging.servicebus.core.ServiceBusTemplate
- All Implemented Interfaces:
SendOperation
Azure Service Bus template to support send
Message
asynchronously.
A defaultEntityType
is required when no entity type is specified in ServiceBusProducerFactory
via related NamespaceProperties
or producer PropertiesSupplier
.
-
Constructor Summary
ConstructorsConstructorDescriptionServiceBusTemplate
(ServiceBusProducerFactory producerFactory) Create an instance using the supplied producer factory.ServiceBusTemplate
(ServiceBusProducerFactory producerFactory, ServiceBusConsumerFactory consumerFactory) Create an instance using the supplied producer factory, processor factory, it supports request-reply pattern. -
Method Summary
Modifier and TypeMethodDescriptionAzureMessageConverter
<com.azure.messaging.servicebus.ServiceBusReceivedMessage, com.azure.messaging.servicebus.ServiceBusMessage> Get the message converter.<U> com.azure.messaging.servicebus.ServiceBusReceivedMessage
sendAndReceive
(String destination, com.azure.spring.cloud.service.servicebus.properties.ServiceBusEntityType entityType, org.springframework.messaging.Message<U> message) Basic RPC pattern usage.<U> com.azure.messaging.servicebus.ServiceBusReceivedMessage
sendAndReceive
(String destination, com.azure.spring.cloud.service.servicebus.properties.ServiceBusEntityType entityType, org.springframework.messaging.Message<U> message, Duration sendTimeout) Basic RPC pattern usage.<U> com.azure.messaging.servicebus.ServiceBusReceivedMessage
sendAndReceive
(String destination, org.springframework.messaging.Message<U> message) Basic RPC pattern usage.void
setDefaultEntityType
(com.azure.spring.cloud.service.servicebus.properties.ServiceBusEntityType entityType) Set the default entity type of the destination to be sent messages to.void
setMessageConverter
(AzureMessageConverter<com.azure.messaging.servicebus.ServiceBusReceivedMessage, com.azure.messaging.servicebus.ServiceBusMessage> messageConverter) Set the message converter to use.void
setRpcSendTimeout
(Duration rpcSendTimeout) Set the timeout for sending message for request-reply pattern.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.azure.spring.messaging.core.SendOperation
send
-
Constructor Details
-
ServiceBusTemplate
Create an instance using the supplied producer factory.- Parameters:
producerFactory
- the producer factory.
-
ServiceBusTemplate
public ServiceBusTemplate(@NonNull ServiceBusProducerFactory producerFactory, ServiceBusConsumerFactory consumerFactory) Create an instance using the supplied producer factory, processor factory, it supports request-reply pattern.- Parameters:
producerFactory
- the producer factory.consumerFactory
- the consumer factory.- Since:
- 5.22.0
-
-
Method Details
-
sendAsync
public <U> Mono<Void> sendAsync(String destination, org.springframework.messaging.Message<U> message) - Specified by:
sendAsync
in interfaceSendOperation
-
sendAndReceive
public <U> com.azure.messaging.servicebus.ServiceBusReceivedMessage sendAndReceive(String destination, org.springframework.messaging.Message<U> message) Basic RPC pattern usage. Send a message to the destination and wait for a reply message from the replay channel, which must be specified by the message headerMessageHeaders.REPLY_CHANNEL
and the session must be enabled; the message headerServiceBusMessageHeaders.REPLY_TO_SESSION_ID
is used to specify a unique reply session ID, if not set, a randomUUID
will be used. Use the default entity type and PRC send timeout.- Type Parameters:
U
- The type of the message payload.- Parameters:
destination
- topic or queue name.message
- Message to be sent to the Service Bus entity.- Returns:
- the reply message of the response. If the reply message fails to be obtained, null is returned.
- Throws:
IllegalStateException
- if sender or receiver is already disposed.- Since:
- 5.22.0
-
sendAndReceive
public <U> com.azure.messaging.servicebus.ServiceBusReceivedMessage sendAndReceive(String destination, com.azure.spring.cloud.service.servicebus.properties.ServiceBusEntityType entityType, org.springframework.messaging.Message<U> message) Basic RPC pattern usage. Send a message to the destination and wait for a reply message from the replay channel, which must be specified by the message headerMessageHeaders.REPLY_CHANNEL
and the session must be enabled; the message headerServiceBusMessageHeaders.REPLY_TO_SESSION_ID
is used to specify a unique reply session ID, if not set, a randomUUID
will be used. Use the default PRC send timeout.- Type Parameters:
U
- The type of the message payload.- Parameters:
destination
- topic or queue name.entityType
- type of Service Bus entity.message
- Message to be sent to the Service Bus entity.- Returns:
- the reply message of the response. If the reply message fails to be obtained, null is returned.
- Throws:
IllegalStateException
- if sender or receiver is already disposed.- Since:
- 5.22.0
-
sendAndReceive
public <U> com.azure.messaging.servicebus.ServiceBusReceivedMessage sendAndReceive(String destination, com.azure.spring.cloud.service.servicebus.properties.ServiceBusEntityType entityType, org.springframework.messaging.Message<U> message, Duration sendTimeout) Basic RPC pattern usage. Send a message to the destination and wait for a reply message from the replay channel, which must be specified by the message headerMessageHeaders.REPLY_CHANNEL
and the session must be enabled; the message headerServiceBusMessageHeaders.REPLY_TO_SESSION_ID
is used to specify a unique reply session ID, if not set, a randomUUID
will be used.- Type Parameters:
U
- The type of the message payload.- Parameters:
destination
- topic or queue name.entityType
- type of Service Bus entity.message
- the message to be sent to the Service Bus entity.sendTimeout
- timeout for sending the message.- Returns:
- the reply message of the response. If the reply message fails to be obtained, null is returned.
- Throws:
IllegalStateException
- if sender or receiver is already disposed.- Since:
- 5.22.0
-
setMessageConverter
public void setMessageConverter(AzureMessageConverter<com.azure.messaging.servicebus.ServiceBusReceivedMessage, com.azure.messaging.servicebus.ServiceBusMessage> messageConverter) Set the message converter to use.- Parameters:
messageConverter
- the message converter.
-
getMessageConverter
public AzureMessageConverter<com.azure.messaging.servicebus.ServiceBusReceivedMessage,com.azure.messaging.servicebus.ServiceBusMessage> getMessageConverter()Get the message converter.- Returns:
- the message converter.
-
setDefaultEntityType
public void setDefaultEntityType(com.azure.spring.cloud.service.servicebus.properties.ServiceBusEntityType entityType) Set the default entity type of the destination to be sent messages to. Required when no entity type is specified inServiceBusProducerFactory
via related theNamespaceProperties
or producerPropertiesSupplier
.- Parameters:
entityType
- the entity type.
-
setRpcSendTimeout
Set the timeout for sending message for request-reply pattern. If not set, the defaultDEFAULT_PRC_SEND_TIMEOUT
will be used.- Parameters:
rpcSendTimeout
- the timeout of sending messages.- Since:
- 5.22.0
-