Class QueueClient
Instantiating an Synchronous Queue Client
QueueClient client = new QueueClientBuilder() .connectionString("connectionstring") .endpoint("endpoint") .buildClient();
View this
for additional ways to construct the client.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Deletes all messages in the queue.com.azure.core.http.rest.Response
<Void> clearMessagesWithResponse
(Duration timeout, com.azure.core.util.Context context) Deletes all messages in the queue.void
create()
Creates a new queue.boolean
Creates a new queue if it does not exist.com.azure.core.http.rest.Response
<Boolean> createIfNotExistsWithResponse
(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a new queue if it does not exist.com.azure.core.http.rest.Response
<Void> createWithResponse
(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a new queue.void
delete()
Permanently deletes the queue.boolean
Permanently deletes the queue if exists.com.azure.core.http.rest.Response
<Boolean> deleteIfExistsWithResponse
(Duration timeout, com.azure.core.util.Context context) Permanently deletes the queue if it exists.void
deleteMessage
(String messageId, String popReceipt) Deletes the specified message in the queuecom.azure.core.http.rest.Response
<Void> deleteMessageWithResponse
(String messageId, String popReceipt, Duration timeout, com.azure.core.util.Context context) Deletes the specified message in the queuecom.azure.core.http.rest.Response
<Void> deleteWithResponse
(Duration timeout, com.azure.core.util.Context context) Permanently deletes the queue.generateSas
(QueueServiceSasSignatureValues queueServiceSasSignatureValues) Generates a service sas for the queue using the specifiedQueueServiceSasSignatureValues
generateSas
(QueueServiceSasSignatureValues queueServiceSasSignatureValues, com.azure.core.util.Context context) Generates a service sas for the queue using the specifiedQueueServiceSasSignatureValues
generateSas
(QueueServiceSasSignatureValues queueServiceSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates a service sas for the queue using the specifiedQueueServiceSasSignatureValues
com.azure.core.http.rest.PagedIterable
<QueueSignedIdentifier> Retrieves stored access policies specified on the queue.Get associated account name.com.azure.core.http.HttpPipeline
Gets theHttpPipeline
powering this client.Gets the message encoding the client is using.Retrieves metadata and approximate message count of the queue.com.azure.core.http.rest.Response
<QueueProperties> getPropertiesWithResponse
(Duration timeout, com.azure.core.util.Context context) Retrieves metadata and approximate message count of the queue.Get the queue name of the client.Get the URL of the storage queue.Gets the service version the client is using.Peeks the first message in the queue.com.azure.core.http.rest.PagedIterable
<PeekedMessageItem> peekMessages
(Integer maxMessages, Duration timeout, com.azure.core.util.Context context) Peek messages from the front of the queue up to the maximum number of messages.Retrieves the first message in the queue and hides it from other operations for 30 seconds.com.azure.core.http.rest.PagedIterable
<QueueMessageItem> receiveMessages
(Integer maxMessages) Retrieves up to the maximum number of messages from the queue and hides them from other operations for 30 seconds.com.azure.core.http.rest.PagedIterable
<QueueMessageItem> receiveMessages
(Integer maxMessages, Duration visibilityTimeout, Duration timeout, com.azure.core.util.Context context) Retrieves up to the maximum number of messages from the queue and hides them from other operations for the timeout period.sendMessage
(com.azure.core.util.BinaryData message) Sends a message that has a time-to-live of 7 days and is instantly visible.sendMessage
(String messageText) Sends a message that has a time-to-live of 7 days and is instantly visible.com.azure.core.http.rest.Response
<SendMessageResult> sendMessageWithResponse
(com.azure.core.util.BinaryData message, Duration visibilityTimeout, Duration timeToLive, Duration timeout, com.azure.core.util.Context context) Sends a message with a given time-to-live and a timeout period where the message is invisible in the queue.com.azure.core.http.rest.Response
<SendMessageResult> sendMessageWithResponse
(String messageText, Duration visibilityTimeout, Duration timeToLive, Duration timeout, com.azure.core.util.Context context) Sends a message with a given time-to-live and a timeout period where the message is invisible in the queue.void
setAccessPolicy
(List<QueueSignedIdentifier> permissions) Sets stored access policies on the queue.com.azure.core.http.rest.Response
<Void> setAccessPolicyWithResponse
(List<QueueSignedIdentifier> permissions, Duration timeout, com.azure.core.util.Context context) Sets stored access policies on the queue.void
setMetadata
(Map<String, String> metadata) Sets the metadata of the queue.com.azure.core.http.rest.Response
<Void> setMetadataWithResponse
(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Sets the metadata of the queue.updateMessage
(String messageId, String popReceipt, String messageText, Duration visibilityTimeout) Updates the specific message in the queue with a new message and resets the visibility timeout.com.azure.core.http.rest.Response
<UpdateMessageResult> updateMessageWithResponse
(String messageId, String popReceipt, String messageText, Duration visibilityTimeout, Duration timeout, com.azure.core.util.Context context) Updates the specific message in the queue with a new message and resets the visibility timeout.
-
Method Details
-
getQueueUrl
Get the URL of the storage queue.- Returns:
- the URL of the storage queue.
-
getServiceVersion
Gets the service version the client is using.- Returns:
- the service version the client is using.
-
getMessageEncoding
Gets the message encoding the client is using.- Returns:
- the message encoding the client is using.
-
getHttpPipeline
public com.azure.core.http.HttpPipeline getHttpPipeline()Gets theHttpPipeline
powering this client.- Returns:
- The pipeline.
-
create
public void create()Creates a new queue.Code Samples
Create a queue
client.create(); System.out.println("Complete creating queue.");
For more information, see the Azure Docs.
- Throws:
QueueStorageException
- If a queue with the same name already exists in the queue service.
-
createWithResponse
public com.azure.core.http.rest.Response<Void> createWithResponse(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a new queue.Code Samples
Create a queue with metadata "queue:metadataMap"
Response<Void> response = client.createWithResponse(Collections.singletonMap("queue", "metadataMap"), Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete creating queue with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
metadata
- Metadata to associate with the queue. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- If a queue with the same name and different metadata already exists in the queue service.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
createIfNotExists
public boolean createIfNotExists()Creates a new queue if it does not exist.Code Samples
Create a queue
boolean result = client.createIfNotExists(); System.out.println("Queue created: " + result);
For more information, see the Azure Docs.
- Returns:
true
if queue is successfully created,false
if queue already exists.
-
createIfNotExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> createIfNotExistsWithResponse(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a new queue if it does not exist.Code Samples
Create a queue with metadata "queue:metadataMap"
Response<Boolean> response = client.createIfNotExistsWithResponse(Collections.singletonMap("queue", "metadataMap"), Duration.ofSeconds(1), new Context(key1, value1)); if (response.getStatusCode() == 409) { System.out.println("Already existed."); } else { System.out.printf("Create completed with status %d%n", response.getStatusCode()); }
For more information, see the Azure Docs.
- Parameters:
metadata
- Metadata to associate with the queue. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. If
Response
's status code is 201, a new queue was successfully created. If status code is 204 or 409, a queue already existed at this location.
-
delete
public void delete()Permanently deletes the queue.Code Samples
Delete a queue
client.delete(); System.out.println("Complete deleting the queue.");
For more information, see the Azure Docs.
- Throws:
QueueStorageException
- If the queue doesn't exist
-
deleteWithResponse
public com.azure.core.http.rest.Response<Void> deleteWithResponse(Duration timeout, com.azure.core.util.Context context) Permanently deletes the queue.Code Samples
Delete a queue
Response<Void> response = client.deleteWithResponse(Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete deleting the queue with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- If the queue doesn't existRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
deleteIfExists
public boolean deleteIfExists()Permanently deletes the queue if exists.Code Samples
Delete a queue
client.deleteIfExists(); System.out.println("Complete deleting the queue.");
For more information, see the Azure Docs.
- Returns:
true
if queue is successfully deleted,false
if queue does not exist.
-
deleteIfExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> deleteIfExistsWithResponse(Duration timeout, com.azure.core.util.Context context) Permanently deletes the queue if it exists.Code Samples
Delete a queue
Response<Boolean> response = client.deleteIfExistsWithResponse(Duration.ofSeconds(1), new Context(key1, value1)); if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.printf("Delete completed with status %d%n", response.getStatusCode()); }
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. If
Response
's status code is 204, the queue was successfully deleted. If status code is 404, the queue does not exist.
-
getProperties
Retrieves metadata and approximate message count of the queue.Code Samples
Get the properties of the queue
QueueProperties properties = client.getProperties(); System.out.printf("Metadata: %s, Approximate message count: %d", properties.getMetadata(), properties.getApproximateMessagesCount());
For more information, see the Azure Docs.
- Returns:
- A response containing a
QueueProperties
value which contains the metadata and approximate messages count of the queue. - Throws:
QueueStorageException
- If the queue doesn't exist
-
getPropertiesWithResponse
public com.azure.core.http.rest.Response<QueueProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context) Retrieves metadata and approximate message count of the queue.Code Samples
Get the properties of the queue
QueueProperties properties = client.getPropertiesWithResponse(Duration.ofSeconds(1), new Context(key1, value1)).getValue(); System.out.printf("Metadata: %s, Approximate message count: %d", properties.getMetadata(), properties.getApproximateMessagesCount());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing a
QueueProperties
value which contains the metadata and approximate messages count of the queue. - Throws:
QueueStorageException
- If the queue doesn't existRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
setMetadata
Sets the metadata of the queue. Passing in anull
value for metadata will clear the metadata associated with the queue.Code Samples
Set the queue's metadata to "queue:metadataMap"
client.setMetadata(Collections.singletonMap("queue", "metadataMap")); System.out.println("Setting metadata completed.");
Clear the queue's metadata
client.setMetadata(null); System.out.println("Clearing metadata completed.");
For more information, see the Azure Docs.
- Parameters:
metadata
- Metadata to set on the queue- Throws:
QueueStorageException
- If the queue doesn't exist
-
setMetadataWithResponse
public com.azure.core.http.rest.Response<Void> setMetadataWithResponse(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Sets the metadata of the queue. Passing in anull
value for metadata will clear the metadata associated with the queue.Code Samples
Set the queue's metadata to "queue:metadataMap"
client.setMetadataWithResponse(Collections.singletonMap("queue", "metadataMap"), Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Setting metadata completed.");
Clear the queue's metadata
Response<Void> response = client.setMetadataWithResponse(null, Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Clearing metadata completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
metadata
- Metadata to set on the queuetimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- If the queue doesn't existRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
getAccessPolicy
Retrieves stored access policies specified on the queue.Code Samples
List the stored access policies
for (QueueSignedIdentifier permission : client.getAccessPolicy()) { System.out.printf("Access policy %s allows these permissions: %s", permission.getId(), permission.getAccessPolicy().getPermissions()); }
For more information, see the Azure Docs.
- Returns:
- The stored access policies specified on the queue.
- Throws:
QueueStorageException
- If the queue doesn't exist
-
setAccessPolicy
Sets stored access policies on the queue.Code Samples
Set a read only stored access policy
QueueAccessPolicy accessPolicy = new QueueAccessPolicy().setPermissions("r") .setStartsOn(OffsetDateTime.now(ZoneOffset.UTC)) .setExpiresOn(OffsetDateTime.now(ZoneOffset.UTC).plusDays(10)); QueueSignedIdentifier permission = new QueueSignedIdentifier().setId("mypolicy").setAccessPolicy(accessPolicy); client.setAccessPolicy(Collections.singletonList(permission)); System.out.println("Setting access policies completed.");
For more information, see the Azure Docs.
- Parameters:
permissions
- Access policies to set on the queue- Throws:
QueueStorageException
- If the queue doesn't exist, a stored access policy doesn't have all fields filled out, or the queue will have more than five policies.
-
setAccessPolicyWithResponse
public com.azure.core.http.rest.Response<Void> setAccessPolicyWithResponse(List<QueueSignedIdentifier> permissions, Duration timeout, com.azure.core.util.Context context) Sets stored access policies on the queue.Code Samples
Set a read only stored access policy
QueueAccessPolicy accessPolicy = new QueueAccessPolicy().setPermissions("r") .setStartsOn(OffsetDateTime.now(ZoneOffset.UTC)) .setExpiresOn(OffsetDateTime.now(ZoneOffset.UTC).plusDays(10)); QueueSignedIdentifier permission = new QueueSignedIdentifier().setId("mypolicy").setAccessPolicy(accessPolicy); Response<Void> response = client.setAccessPolicyWithResponse(Collections.singletonList(permission), Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Setting access policies completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
permissions
- Access policies to set on the queuetimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- If the queue doesn't exist, a stored access policy doesn't have all fields filled out, or the queue will have more than five policies.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
clearMessages
public void clearMessages()Deletes all messages in the queue.Code Samples
Clear the messages
client.clearMessages(); System.out.println("Clearing messages completed.");
For more information, see the Azure Docs.
- Throws:
QueueStorageException
- If the queue doesn't exist
-
clearMessagesWithResponse
public com.azure.core.http.rest.Response<Void> clearMessagesWithResponse(Duration timeout, com.azure.core.util.Context context) Deletes all messages in the queue.Code Samples
Clear the messages
Response<Void> response = client.clearMessagesWithResponse(Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Clearing messages completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- If the queue doesn't existRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
sendMessage
Sends a message that has a time-to-live of 7 days and is instantly visible.Code Samples
Sends a message of "Hello, Azure"
SendMessageResult response = client.sendMessage("hello msg"); System.out.println("Complete enqueuing the message with message Id" + response.getMessageId());
For more information, see the Azure Docs.
- Parameters:
messageText
- Message text- Returns:
- A
SendMessageResult
value that contains themessageId
andpopReceipt
that are used to interact with the message and other metadata about the enqueued message. - Throws:
QueueStorageException
- If the queue doesn't exist
-
sendMessage
Sends a message that has a time-to-live of 7 days and is instantly visible.Code Samples
Sends a message of "Hello, Azure"
SendMessageResult response = client.sendMessage(BinaryData.fromString("Hello msg")); System.out.println("Complete enqueuing the message with message Id" + response.getMessageId());
For more information, see the Azure Docs.
- Parameters:
message
- Message content- Returns:
- A
SendMessageResult
value that contains themessageId
andpopReceipt
that are used to interact with the message and other metadata about the enqueued message. - Throws:
QueueStorageException
- If the queue doesn't exist
-
sendMessageWithResponse
public com.azure.core.http.rest.Response<SendMessageResult> sendMessageWithResponse(String messageText, Duration visibilityTimeout, Duration timeToLive, Duration timeout, com.azure.core.util.Context context) Sends a message with a given time-to-live and a timeout period where the message is invisible in the queue.Code Samples
Add a message of "Hello, Azure" that has a timeout of 5 seconds
SendMessageResult sentMessageItem = client.sendMessageWithResponse("Hello, Azure", Duration.ofSeconds(5), null, Duration.ofSeconds(1), new Context(key1, value1)).getValue(); System.out.printf("Message %s expires at %s", sentMessageItem.getMessageId(), sentMessageItem.getExpirationTime());
Add a message of "Goodbye, Azure" that has a time to live of 5 seconds
SendMessageResult enqueuedMessage = client.sendMessageWithResponse("Goodbye, Azure", null, Duration.ofSeconds(5), Duration.ofSeconds(1), new Context(key1, value1)).getValue(); System.out.printf("Message %s expires at %s", enqueuedMessage.getMessageId(), enqueuedMessage.getExpirationTime());
For more information, see the Azure Docs.
- Parameters:
messageText
- Message textvisibilityTimeout
- Optional. The timeout period for how long the message is invisible in the queue. If unset the value will default to 0 and the message will be instantly visible. The timeout must be between 0 seconds and 7 days.timeToLive
- Optional. How long the message will stay alive in the queue. If unset the value will default to 7 days, ifDuration.ofSeconds(-1)
is passed the message will not expire. The time to live must beDuration.ofSeconds(-1)
or any positive number of seconds.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
SendMessageResult
value that contains themessageId
andpopReceipt
that are used to interact with the message and other metadata about the enqueued message. - Throws:
QueueStorageException
- If the queue doesn't exist or thevisibilityTimeout
ortimeToLive
are outside of the allowed limits.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
sendMessageWithResponse
public com.azure.core.http.rest.Response<SendMessageResult> sendMessageWithResponse(com.azure.core.util.BinaryData message, Duration visibilityTimeout, Duration timeToLive, Duration timeout, com.azure.core.util.Context context) Sends a message with a given time-to-live and a timeout period where the message is invisible in the queue.Code Samples
Add a message of "Hello, Azure" that has a timeout of 5 seconds
SendMessageResult sentMessageItem = client.sendMessageWithResponse(BinaryData.fromString("Hello, Azure"), Duration.ofSeconds(5), null, Duration.ofSeconds(1), new Context(key1, value1)).getValue(); System.out.printf("Message %s expires at %s", sentMessageItem.getMessageId(), sentMessageItem.getExpirationTime());
Add a message of "Goodbye, Azure" that has a time to live of 5 seconds
SendMessageResult enqueuedMessage = client.sendMessageWithResponse(BinaryData.fromString("Goodbye, Azure"), null, Duration.ofSeconds(5), Duration.ofSeconds(1), new Context(key1, value1)).getValue(); System.out.printf("Message %s expires at %s", enqueuedMessage.getMessageId(), enqueuedMessage.getExpirationTime());
For more information, see the Azure Docs.
- Parameters:
message
- Message contentvisibilityTimeout
- Optional. The timeout period for how long the message is invisible in the queue. If unset the value will default to 0 and the message will be instantly visible. The timeout must be between 0 seconds and 7 days.timeToLive
- Optional. How long the message will stay alive in the queue. If unset the value will default to 7 days, ifDuration.ofSeconds(-1)
is passed the message will not expire. The time to live must beDuration.ofSeconds(-1)
or any positive number of seconds.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
SendMessageResult
value that contains themessageId
andpopReceipt
that are used to interact with the message and other metadata about the enqueued message. - Throws:
QueueStorageException
- If the queue doesn't exist or thevisibilityTimeout
ortimeToLive
are outside of the allowed limits.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
receiveMessage
Retrieves the first message in the queue and hides it from other operations for 30 seconds.Code Samples
Receive a message
QueueMessageItem queueMessageItem = client.receiveMessage(); System.out.println("Complete receiving the message: " + queueMessageItem.getMessageId());
For more information, see the Azure Docs.
- Returns:
- The first
MessageItem
in the queue, it containsmessageId
andpopReceipt
used to interact with the message, additionally it contains other metadata about the message. - Throws:
QueueStorageException
- If the queue doesn't exist
-
receiveMessages
public com.azure.core.http.rest.PagedIterable<QueueMessageItem> receiveMessages(Integer maxMessages) Retrieves up to the maximum number of messages from the queue and hides them from other operations for 30 seconds.Code Samples
Receive up to 5 messages
for (QueueMessageItem message : client.receiveMessages(5)) { System.out.printf("Received %s and it becomes visible at %s", message.getMessageId(), message.getTimeNextVisible()); }
For more information, see the Azure Docs.
- Parameters:
maxMessages
- Optional. Maximum number of messages to get, if there are less messages exist in the queue than requested all the messages will be returned. If left empty only 1 message will be retrieved, the allowed range is 1 to 32 messages.- Returns:
- Up to
maxMessages
ReceiveMessageItem
from the queue. Each ReceiveMessageItem containsmessageId
andpopReceipt
used to interact with the message and other metadata about the message. - Throws:
QueueStorageException
- If the queue doesn't exist ormaxMessages
is outside of the allowed bounds
-
receiveMessages
public com.azure.core.http.rest.PagedIterable<QueueMessageItem> receiveMessages(Integer maxMessages, Duration visibilityTimeout, Duration timeout, com.azure.core.util.Context context) Retrieves up to the maximum number of messages from the queue and hides them from other operations for the timeout period.Code Samples
Receive up to 5 messages and give them a 60 second timeout period
for (QueueMessageItem message : client.receiveMessages(5, Duration.ofSeconds(60), Duration.ofSeconds(1), new Context(key1, value1))) { System.out.printf("Received %s and it becomes visible at %s", message.getMessageId(), message.getTimeNextVisible()); }
For more information, see the Azure Docs.
- Parameters:
maxMessages
- Optional. Maximum number of messages to get, if there are less messages exist in the queue than requested all the messages will be returned. If left empty only 1 message will be retrieved, the allowed range is 1 to 32 messages.visibilityTimeout
- Optional. The timeout period for how long the message is invisible in the queue. If left empty the received messages will be invisible for 30 seconds. The timeout must be between 1 second and 7 days.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Up to
maxMessages
DequeuedMessages
from the queue. Each DeqeuedMessage containsmessageId
andpopReceipt
used to interact with the message and other metadata about the message. - Throws:
QueueStorageException
- If the queue doesn't exist ormaxMessages
orvisibilityTimeout
is outside of the allowed boundsRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
peekMessage
Peeks the first message in the queue. Peeked messages don't contain the necessary information needed to interact with the message nor will it hide messages from other operations on the queue.Code Samples
Peek the first message
PeekedMessageItem peekedMessageItem = client.peekMessage(); System.out.println("Complete peeking the message: " + peekedMessageItem.getBody().toString());
For more information, see the Azure Docs.
- Returns:
- A
PeekedMessageItem
that contains metadata about the message.
-
peekMessages
public com.azure.core.http.rest.PagedIterable<PeekedMessageItem> peekMessages(Integer maxMessages, Duration timeout, com.azure.core.util.Context context) Peek messages from the front of the queue up to the maximum number of messages. Peeked messages don't contain the necessary information needed to interact with the message nor will it hide messages from other operations on the queue.Code Samples
Peek up to the first five messages
client.peekMessages(5, Duration.ofSeconds(1), new Context(key1, value1)).forEach( peekMessage -> System.out.printf("Peeked message %s has been received %d times", peekMessage.getMessageId(), peekMessage.getDequeueCount()) );
For more information, see the Azure Docs.
- Parameters:
maxMessages
- Optional. Maximum number of messages to peek, if there are less messages exist in the queue than requested all the messages will be peeked. If left empty only 1 message will be peeked, the allowed range is 1 to 32 messages.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Up to
maxMessages
PeekedMessages
from the queue. Each PeekedMessage contains metadata about the message. - Throws:
QueueStorageException
- If the queue doesn't exist ormaxMessages
is outside of the allowed boundsRuntimeException
- if the operation doesn't complete before the timeout concludes.
-
updateMessage
public UpdateMessageResult updateMessage(String messageId, String popReceipt, String messageText, Duration visibilityTimeout) Updates the specific message in the queue with a new message and resets the visibility timeout.Code Samples
Dequeue the first message and update it to "Hello again, Azure" and hide it for 5 seconds
QueueMessageItem queueMessageItem = client.receiveMessage(); UpdateMessageResult result = client.updateMessage(queueMessageItem.getMessageId(), queueMessageItem.getPopReceipt(), "newText", null); System.out.println("Complete updating the message with the receipt " + result.getPopReceipt());
For more information, see the Azure Docs.
- Parameters:
messageId
- Id of the message to updatepopReceipt
- Unique identifier that must match for the message to be updatedmessageText
- Updated value for the messagevisibilityTimeout
- The timeout period for how long the message is invisible in the queue in seconds. The timeout period must be between 1 second and 7 days. The default value is Duration.ZERO.- Returns:
- A
UpdateMessageResult
that contains the newpopReceipt
to interact with the message, additionally contains the updated metadata about the message. - Throws:
QueueStorageException
- If the queue or messageId don't exist, the popReceipt doesn't match on the message, or thevisibilityTimeout
is outside the allowed bounds.
-
updateMessageWithResponse
public com.azure.core.http.rest.Response<UpdateMessageResult> updateMessageWithResponse(String messageId, String popReceipt, String messageText, Duration visibilityTimeout, Duration timeout, com.azure.core.util.Context context) Updates the specific message in the queue with a new message and resets the visibility timeout.Code Samples
Dequeue the first message and update it to "Hello again, Azure" and hide it for 5 seconds
QueueMessageItem queueMessageItem = client.receiveMessage(); Response<UpdateMessageResult> response = client.updateMessageWithResponse(queueMessageItem.getMessageId(), queueMessageItem.getPopReceipt(), "newText", null, Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete updating the message with status code " + response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
messageId
- Id of the message to updatepopReceipt
- Unique identifier that must match for the message to be updatedmessageText
- Updated value for the messagevisibilityTimeout
- The timeout period for how long the message is invisible in the queue in seconds. The timeout period must be between 1 second and 7 days. The default value is Duration.ZERO.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the
UpdateMessageResult
that contains the newpopReceipt
to interact with the message, additionally contains the updated metadata about the message. - Throws:
QueueStorageException
- If the queue or messageId don't exist, the popReceipt doesn't match on the message, or thevisibilityTimeout
is outside the allowed bounds.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
deleteMessage
Deletes the specified message in the queueCode Samples
Delete the first message
QueueMessageItem queueMessageItem = client.receiveMessage(); client.deleteMessage(queueMessageItem.getMessageId(), queueMessageItem.getPopReceipt()); System.out.println("Complete deleting the message.");
For more information, see the Azure Docs.
- Parameters:
messageId
- Id of the message to deletedpopReceipt
- Unique identifier that must match for the message to be deleted- Throws:
QueueStorageException
- If the queue or messageId don't exist or the popReceipt doesn't match on the message.
-
deleteMessageWithResponse
public com.azure.core.http.rest.Response<Void> deleteMessageWithResponse(String messageId, String popReceipt, Duration timeout, com.azure.core.util.Context context) Deletes the specified message in the queueCode Samples
Delete the first message
QueueMessageItem queueMessageItem = client.receiveMessage(); Response<Void> response = client.deleteMessageWithResponse(queueMessageItem.getMessageId(), queueMessageItem.getPopReceipt(), Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Complete deleting the message with status code " + response.getStatusCode());
For more information, see the Azure Docs.
- Parameters:
messageId
- Id of the message to deletedpopReceipt
- Unique identifier that must match for the message to be deletedtimeout
- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeException
will be thrown.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
QueueStorageException
- If the queue or messageId don't exist or the popReceipt doesn't match on the message.RuntimeException
- if the operation doesn't complete before the timeout concludes.
-
getQueueName
Get the queue name of the client.Code Samples
String queueName = client.getQueueName(); System.out.println("The name of the queue is " + queueName);
- Returns:
- The name of the queue.
-
getAccountName
Get associated account name.- Returns:
- account name associated with this storage resource.
-
generateSas
Generates a service sas for the queue using the specifiedQueueServiceSasSignatureValues
Note : The client must be authenticated via
StorageSharedKeyCredential
See
QueueServiceSasSignatureValues
for more information on how to construct a service SAS.Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1); QueueSasPermission permission = new QueueSasPermission().setReadPermission(true); QueueServiceSasSignatureValues values = new QueueServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
- Parameters:
queueServiceSasSignatureValues
-QueueServiceSasSignatureValues
- Returns:
- A
String
representing the SAS query parameters.
-
generateSas
public String generateSas(QueueServiceSasSignatureValues queueServiceSasSignatureValues, com.azure.core.util.Context context) Generates a service sas for the queue using the specifiedQueueServiceSasSignatureValues
Note : The client must be authenticated via
StorageSharedKeyCredential
See
QueueServiceSasSignatureValues
for more information on how to construct a service SAS.Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1); QueueSasPermission permission = new QueueSasPermission().setReadPermission(true); QueueServiceSasSignatureValues values = new QueueServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); // Client must be authenticated via StorageSharedKeyCredential client.generateSas(values, new Context("key", "value"));
- Parameters:
queueServiceSasSignatureValues
-QueueServiceSasSignatureValues
context
- Additional context that is passed through the code when generating a SAS.- Returns:
- A
String
representing the SAS query parameters.
-
generateSas
public String generateSas(QueueServiceSasSignatureValues queueServiceSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates a service sas for the queue using the specifiedQueueServiceSasSignatureValues
Note : The client must be authenticated via
StorageSharedKeyCredential
See
QueueServiceSasSignatureValues
for more information on how to construct a service SAS.- Parameters:
queueServiceSasSignatureValues
-QueueServiceSasSignatureValues
stringToSignHandler
- For debugging purposes only. Returns the string to sign that was used to generate the signature.context
- Additional context that is passed through the code when generating a SAS.- Returns:
- A
String
representing the SAS query parameters.
-