use of com.microsoft.azure.storage.queue.CloudQueueClient in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method dequeueFirstQueueMessage.
@NotNull
public QueueMessage dequeueFirstQueueMessage(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
CloudQueueMessage cqm = cloudQueue.retrieveMessage();
String id = "";
String content = "";
Calendar insertionTime = new GregorianCalendar();
Calendar expirationTime = new GregorianCalendar();
int dequeueCount = 0;
if (cqm != null) {
id = Strings.nullToEmpty(cqm.getId());
content = Strings.nullToEmpty(cqm.getMessageContentAsString());
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
dequeueCount = cqm.getDequeueCount();
}
QueueMessage queueMessage = new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount);
if (cqm != null) {
cloudQueue.deleteMessage(cqm);
}
return queueMessage;
} catch (Throwable t) {
throw new AzureCmdException("Error dequeuing the first Queue Message", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueueClient in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method clearQueue.
public void clearQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queue.getName());
cloudQueue.clear();
} catch (Throwable t) {
throw new AzureCmdException("Error clearing the Queue", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueueClient in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createQueue.
@NotNull
public Queue createQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queue.getName());
cloudQueue.createIfNotExists();
cloudQueue.downloadAttributes();
String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
long approximateMessageCount = cloudQueue.getApproximateMessageCount();
queue.setUri(uri);
queue.setApproximateMessageCount(approximateMessageCount);
return queue;
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Queue", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueueClient in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getQueueMessages.
@NotNull
public List<QueueMessage> getQueueMessages(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
List<QueueMessage> qmList = new ArrayList<QueueMessage>();
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
for (CloudQueueMessage cqm : cloudQueue.peekMessages(32)) {
String id = Strings.nullToEmpty(cqm.getId());
String content = Strings.nullToEmpty(cqm.getMessageContentAsString());
Calendar insertionTime = new GregorianCalendar();
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
Calendar expirationTime = new GregorianCalendar();
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
int dequeueCount = cqm.getDequeueCount();
qmList.add(new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount));
}
return qmList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Queue Message list", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueueClient in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createQueueMessage.
public void createQueueMessage(@NotNull StorageAccount storageAccount, @NotNull QueueMessage queueMessage, int timeToLiveInSeconds) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queueMessage.getQueueName());
cloudQueue.addMessage(new CloudQueueMessage(queueMessage.getContent()), timeToLiveInSeconds, 0, null, null);
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Queue Message", t);
}
}
Aggregations