Search in sources :

Example 1 with CloudQueueClient

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);
    }
}
Also used : QueueMessage(com.microsoft.tooling.msservices.model.storage.QueueMessage) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 2 with CloudQueueClient

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);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 3 with CloudQueueClient

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);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 4 with CloudQueueClient

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);
    }
}
Also used : QueueMessage(com.microsoft.tooling.msservices.model.storage.QueueMessage) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 5 with CloudQueueClient

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);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Aggregations

CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)7 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)7 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)7 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)4 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)3 QueueMessage (com.microsoft.tooling.msservices.model.storage.QueueMessage)2 Queue (com.microsoft.tooling.msservices.model.storage.Queue)1