Package com.microsoft.azure.servicebus
Class TopicClient
- java.lang.Object
-
- com.microsoft.azure.servicebus.primitives.ClientEntity
-
- com.microsoft.azure.servicebus.TopicClient
-
- All Implemented Interfaces:
ICloseable
,IMessageBrowser
,IMessageEntityClient
,IMessageSender
,ITopicClient
public final class TopicClient extends ClientEntity implements ITopicClient
The topic client that interacts with service bus topic.
-
-
Constructor Summary
Constructors Constructor Description TopicClient(ConnectionStringBuilder amqpConnectionStringBuilder)
TopicClient(String namespace, String topicPath, ClientSettings clientSettings)
TopicClient(URI namespaceEndpointURI, String topicPath, ClientSettings clientSettings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelScheduledMessage(long sequenceNumber)
Cancels the enqueuing of an already sent scheduled message, if it was not already enqueued.CompletableFuture<Void>
cancelScheduledMessageAsync(long sequenceNumber)
Cancels the enqueuing of an already sent scheduled message, if it was not already enqueued.String
getEntityPath()
Gets the path of the entity this client is sending messages to or receiving messages from.String
getTopicName()
Get the name of the topicprotected CompletableFuture<Void>
onClose()
IMessage
peek()
reads next the active message without changing the state of the receiver or the message source.IMessage
peek(long fromSequenceNumber)
Reads next the active message without changing the state of the receiver or the message source.CompletableFuture<IMessage>
peekAsync()
Asynchronously reads the active messages without changing the state of the receiver or the message source.CompletableFuture<IMessage>
peekAsync(long fromSequenceNumber)
Asynchronously reads next the active message without changing the state of the receiver or the message source.Collection<IMessage>
peekBatch(int messageCount)
Reads next batch of the active messages without changing the state of the receiver or the message source.Collection<IMessage>
peekBatch(long fromSequenceNumber, int messageCount)
Reads next batch of the active messages without changing the state of the receiver or the message source.CompletableFuture<Collection<IMessage>>
peekBatchAsync(int messageCount)
Asynchronously reads the next batch of active messages without changing the state of the receiver or the message source.CompletableFuture<Collection<IMessage>>
peekBatchAsync(long fromSequenceNumber, int messageCount)
Asynchronously reads the next batch of active messages without changing the state of the receiver or the message source.long
scheduleMessage(IMessage message, Instant scheduledEnqueueTimeUtc)
Sends a scheduled message to the Azure Service Bus entity this sender is connected to.long
scheduleMessage(IMessage message, Instant scheduledEnqueueTimeUtc, TransactionContext transaction)
Sends a scheduled message to the Azure Service Bus entity this sender is connected to.CompletableFuture<Long>
scheduleMessageAsync(IMessage message, Instant scheduledEnqueueTimeUtc)
Sends a scheduled message to the Azure Service Bus entity this sender is connected to.CompletableFuture<Long>
scheduleMessageAsync(IMessage message, Instant scheduledEnqueueTimeUtc, TransactionContext transaction)
Sends a scheduled message to the Azure Service Bus entity this sender is connected to.void
send(IMessage message)
Sends a message to the Azure Service Bus entity this sender is connected to.void
send(IMessage message, TransactionContext transaction)
Sends a message to the Azure Service Bus entity this sender is connected to.CompletableFuture<Void>
sendAsync(IMessage message)
Sends a message to the Azure Service Bus entity this sender is connected to.CompletableFuture<Void>
sendAsync(IMessage message, TransactionContext transaction)
Sends a message to the Azure Service Bus entity this sender is connected to.void
sendBatch(Collection<? extends IMessage> messages)
Sends a batch of messages to the Azure Service Bus entity this sender is connected to.void
sendBatch(Collection<? extends IMessage> messages, TransactionContext transaction)
Sends a batch of messages to the Azure Service Bus entity this sender is connected to.CompletableFuture<Void>
sendBatchAsync(Collection<? extends IMessage> messages)
Sends a batch of messages to the Azure Service Bus entity this sender is connected to.CompletableFuture<Void>
sendBatchAsync(Collection<? extends IMessage> messages, TransactionContext transaction)
Sends a batch of messages to the Azure Service Bus entity this sender is connected to.-
Methods inherited from class com.microsoft.azure.servicebus.primitives.ClientEntity
close, closeAsync, finalize, getClientId, getIsClosed, getIsClosingOrClosed, setClosed, setClosing, throwIfClosed
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.microsoft.azure.servicebus.ICloseable
close, closeAsync
-
-
-
-
Constructor Detail
-
TopicClient
public TopicClient(ConnectionStringBuilder amqpConnectionStringBuilder) throws InterruptedException, ServiceBusException
-
TopicClient
public TopicClient(String namespace, String topicPath, ClientSettings clientSettings) throws InterruptedException, ServiceBusException
-
TopicClient
public TopicClient(URI namespaceEndpointURI, String topicPath, ClientSettings clientSettings) throws InterruptedException, ServiceBusException
-
-
Method Detail
-
send
public void send(IMessage message) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
Sends a message to the Azure Service Bus entity this sender is connected to. This method blocks until the message is sent to the entity. Calling this method is equivalent to callingsendAsync(message).get()
. For better performance, use async methods.- Specified by:
send
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entity- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if message couldn't be sent to the entity
-
send
public void send(IMessage message, TransactionContext transaction) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
Sends a message to the Azure Service Bus entity this sender is connected to. This method blocks until the message is sent to the entity. Calling this method is equivalent to callingsendAsync(message).get()
. For better performance, use async methods.- Specified by:
send
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entitytransaction
-TransactionContext
which this operation should enlist to.- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if message couldn't be sent to the entity
-
sendBatch
public void sendBatch(Collection<? extends IMessage> messages) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
Sends a batch of messages to the Azure Service Bus entity this sender is connected to. This method blocks until the batch is sent to the entity. Calling this method is equivalent to callingsendBatchAsync(messages).get()
. For better performance, use async methods. When called on partitioned entities, messages meant for different partitions cannot be batched together.- Specified by:
sendBatch
in interfaceIMessageSender
- Parameters:
messages
- collection of messages to be sent to the entity- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if the batch couldn't be sent to the entity
-
sendBatch
public void sendBatch(Collection<? extends IMessage> messages, TransactionContext transaction) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
Sends a batch of messages to the Azure Service Bus entity this sender is connected to. This method blocks until the batch is sent to the entity. Calling this method is equivalent to callingsendBatchAsync(messages).get()
. For better performance, use async methods. When called on partitioned entities, messages meant for different partitions cannot be batched together.- Specified by:
sendBatch
in interfaceIMessageSender
- Parameters:
messages
- collection of messages to be sent to the entitytransaction
-TransactionContext
which this operation should enlist to.- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if the batch couldn't be sent to the entity
-
sendAsync
public CompletableFuture<Void> sendAsync(IMessage message)
Description copied from interface:IMessageSender
Sends a message to the Azure Service Bus entity this sender is connected to. This is an asynchronous method returning a CompletableFuture which completes when the message is sent to the entity.- Specified by:
sendAsync
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entity- Returns:
- a CompletableFuture representing the pending send
-
sendAsync
public CompletableFuture<Void> sendAsync(IMessage message, TransactionContext transaction)
Description copied from interface:IMessageSender
Sends a message to the Azure Service Bus entity this sender is connected to. This is an asynchronous method returning a CompletableFuture which completes when the message is sent to the entity.- Specified by:
sendAsync
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entitytransaction
-TransactionContext
which this operation should enlist to.- Returns:
- a CompletableFuture representing the pending send
-
sendBatchAsync
public CompletableFuture<Void> sendBatchAsync(Collection<? extends IMessage> messages)
Description copied from interface:IMessageSender
Sends a batch of messages to the Azure Service Bus entity this sender is connected to. This is an asynchronous method returning a CompletableFuture which completes when the batch is sent to the entity. When called on partitioned entities, messages meant for different partitions cannot be batched together.- Specified by:
sendBatchAsync
in interfaceIMessageSender
- Parameters:
messages
- collection of messages to be sent to the entity- Returns:
- a CompletableFuture representing the pending send
-
sendBatchAsync
public CompletableFuture<Void> sendBatchAsync(Collection<? extends IMessage> messages, TransactionContext transaction)
Description copied from interface:IMessageSender
Sends a batch of messages to the Azure Service Bus entity this sender is connected to. This is an asynchronous method returning a CompletableFuture which completes when the batch is sent to the entity. When called on partitioned entities, messages meant for different partitions cannot be batched together.- Specified by:
sendBatchAsync
in interfaceIMessageSender
- Parameters:
messages
- collection of messages to be sent to the entitytransaction
-TransactionContext
which this operation should enlist to.- Returns:
- a CompletableFuture representing the pending send
-
scheduleMessageAsync
public CompletableFuture<Long> scheduleMessageAsync(IMessage message, Instant scheduledEnqueueTimeUtc)
Description copied from interface:IMessageSender
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. This is an asynchronous method returning a CompletableFuture which completes when the message is sent to the entity. The CompletableFuture, on completion, returns the sequence number of the scheduled message which can be used to cancel the scheduling of the message.- Specified by:
scheduleMessageAsync
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entityscheduledEnqueueTimeUtc
- instant at which the message should be enqueued in the entity- Returns:
- a CompletableFuture representing the pending send, which returns the sequence number of the scheduled message. This sequence number can be used to cancel the scheduling of the message.
-
scheduleMessageAsync
public CompletableFuture<Long> scheduleMessageAsync(IMessage message, Instant scheduledEnqueueTimeUtc, TransactionContext transaction)
Description copied from interface:IMessageSender
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. This is an asynchronous method returning a CompletableFuture which completes when the message is sent to the entity. The CompletableFuture, on completion, returns the sequence number of the scheduled message which can be used to cancel the scheduling of the message.- Specified by:
scheduleMessageAsync
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entityscheduledEnqueueTimeUtc
- instant at which the message should be enqueued in the entitytransaction
-TransactionContext
which this operation should enlist to.- Returns:
- a CompletableFuture representing the pending send, which returns the sequence number of the scheduled message. This sequence number can be used to cancel the scheduling of the message.
-
cancelScheduledMessageAsync
public CompletableFuture<Void> cancelScheduledMessageAsync(long sequenceNumber)
Description copied from interface:IMessageSender
Cancels the enqueuing of an already sent scheduled message, if it was not already enqueued. This is an asynchronous method returning a CompletableFuture which completes when the message is cancelled.- Specified by:
cancelScheduledMessageAsync
in interfaceIMessageSender
- Parameters:
sequenceNumber
- sequence number of the scheduled message- Returns:
- a CompletableFuture representing the pending cancellation
-
scheduleMessage
public long scheduleMessage(IMessage message, Instant scheduledEnqueueTimeUtc) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
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. This method blocks until the message is sent to the entity. Calling this method is equivalent to callingscheduleMessageAsync(message, scheduledEnqueueTimeUtc).get()
. For better performance, use async methods.- Specified by:
scheduleMessage
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entityscheduledEnqueueTimeUtc
- instant at which the message should be enqueued in the entity- Returns:
- sequence number of the scheduled message
- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if message couldn't be sent to the entity
-
scheduleMessage
public long scheduleMessage(IMessage message, Instant scheduledEnqueueTimeUtc, TransactionContext transaction) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
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. This method blocks until the message is sent to the entity. Calling this method is equivalent to callingscheduleMessageAsync(message, scheduledEnqueueTimeUtc).get()
. For better performance, use async methods.- Specified by:
scheduleMessage
in interfaceIMessageSender
- Parameters:
message
- message to be sent to the entityscheduledEnqueueTimeUtc
- instant at which the message should be enqueued in the entitytransaction
-TransactionContext
which this operation should enlist to.- Returns:
- sequence number of the scheduled message
- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if message couldn't be sent to the entity
-
cancelScheduledMessage
public void cancelScheduledMessage(long sequenceNumber) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageSender
Cancels the enqueuing of an already sent scheduled message, if it was not already enqueued. This method blocks until the message is sent to the entity. Calling this method is equivalent to callingcancelScheduledMessageAsync(sequenceNumber).get()
. For better performance, use async methods.- Specified by:
cancelScheduledMessage
in interfaceIMessageSender
- Parameters:
sequenceNumber
- sequence number of the scheduled message- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if scheduled message couldn't be cancelled
-
getEntityPath
public String getEntityPath()
Description copied from interface:IMessageEntityClient
Gets the path of the entity this client is sending messages to or receiving messages from.- Specified by:
getEntityPath
in interfaceIMessageEntityClient
- Returns:
- path of the entity this client is connecting to
-
peek
public IMessage peek() throws InterruptedException, ServiceBusException
Description copied from interface:IMessageBrowser
reads next the active message without changing the state of the receiver or the message source. The first call toIMessageBrowser.peek()
fetches the first active message for this receiver. Each subsequent call fetches the subsequent message in the entity.- Specified by:
peek
in interfaceIMessageBrowser
- Returns:
Message
peeked- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if peek failed
-
peek
public IMessage peek(long fromSequenceNumber) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageBrowser
Reads next the active message without changing the state of the receiver or the message source.- Specified by:
peek
in interfaceIMessageBrowser
- Parameters:
fromSequenceNumber
- The sequence number from where to read the message.- Returns:
Message
peeked- Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if peek failed
-
peekBatch
public Collection<IMessage> peekBatch(int messageCount) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageBrowser
Reads next batch of the active messages without changing the state of the receiver or the message source.- Specified by:
peekBatch
in interfaceIMessageBrowser
- Parameters:
messageCount
- The number of messages.- Returns:
- Batch of
Message
peeked - Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if peek failed
-
peekBatch
public Collection<IMessage> peekBatch(long fromSequenceNumber, int messageCount) throws InterruptedException, ServiceBusException
Description copied from interface:IMessageBrowser
Reads next batch of the active messages without changing the state of the receiver or the message source.- Specified by:
peekBatch
in interfaceIMessageBrowser
- Parameters:
fromSequenceNumber
- The sequence number from where to read the message.messageCount
- The number of messages.- Returns:
- Batch of
Message
peeked - Throws:
InterruptedException
- if the current thread was interrupted while waitingServiceBusException
- if peek failed
-
peekAsync
public CompletableFuture<IMessage> peekAsync()
Description copied from interface:IMessageBrowser
Asynchronously reads the active messages without changing the state of the receiver or the message source.- Specified by:
peekAsync
in interfaceIMessageBrowser
- Returns:
Message
peeked
-
peekAsync
public CompletableFuture<IMessage> peekAsync(long fromSequenceNumber)
Description copied from interface:IMessageBrowser
Asynchronously reads next the active message without changing the state of the receiver or the message source.- Specified by:
peekAsync
in interfaceIMessageBrowser
- Parameters:
fromSequenceNumber
- The sequence number from where to read the message.- Returns:
- CompletableFuture that returns
Message
peeked.
-
peekBatchAsync
public CompletableFuture<Collection<IMessage>> peekBatchAsync(int messageCount)
Description copied from interface:IMessageBrowser
Asynchronously reads the next batch of active messages without changing the state of the receiver or the message source.- Specified by:
peekBatchAsync
in interfaceIMessageBrowser
- Parameters:
messageCount
- The number of messages.- Returns:
- CompletableFuture that returns batch of
Message
peeked.
-
peekBatchAsync
public CompletableFuture<Collection<IMessage>> peekBatchAsync(long fromSequenceNumber, int messageCount)
Description copied from interface:IMessageBrowser
Asynchronously reads the next batch of active messages without changing the state of the receiver or the message source.- Specified by:
peekBatchAsync
in interfaceIMessageBrowser
- Parameters:
fromSequenceNumber
- The sequence number from where to read the message.messageCount
- The number of messages.- Returns:
- CompletableFuture that returns batch of
Message
peeked.
-
onClose
protected CompletableFuture<Void> onClose()
- Specified by:
onClose
in classClientEntity
-
getTopicName
public String getTopicName()
Description copied from interface:ITopicClient
Get the name of the topic- Specified by:
getTopicName
in interfaceITopicClient
- Returns:
- the name of the topic
-
-