Search in sources :

Example 11 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue 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)

Example 12 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getQueues.

@NotNull
public List<Queue> getQueues(@NotNull StorageAccount storageAccount) throws AzureCmdException {
    List<Queue> qList = new ArrayList<Queue>();
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        for (CloudQueue cloudQueue : client.listQueues(null, QueueListingDetails.ALL, null, null)) {
            String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
            qList.add(new Queue(Strings.nullToEmpty(cloudQueue.getName()), uri, cloudQueue.getApproximateMessageCount()));
        }
        return qList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Queue list", t);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Queue(com.microsoft.tooling.msservices.model.storage.Queue) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 13 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method deleteQueue.

public void deleteQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        CloudQueue cloudQueue = client.getQueueReference(queue.getName());
        cloudQueue.deleteIfExists();
    } catch (Throwable t) {
        throw new AzureCmdException("Error deleting 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 14 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project camel by apache.

the class QueueServiceComponent method checkCredentials.

private void checkCredentials(QueueServiceConfiguration cfg) {
    CloudQueue client = cfg.getAzureQueueClient();
    StorageCredentials creds = client == null ? cfg.getCredentials() : client.getServiceClient().getCredentials();
    if (creds == null) {
        throw new IllegalArgumentException("Credentials must be specified.");
    }
}
Also used : StorageCredentials(com.microsoft.azure.storage.StorageCredentials) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 15 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project camel by apache.

the class QueueServiceProducer method updateMessage.

private void updateMessage(Exchange exchange) throws Exception {
    CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
    QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
    CloudQueueMessage message = getCloudQueueMessage(exchange);
    LOG.trace("Updating the message in the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange);
    EnumSet<MessageUpdateFields> fields = null;
    Object fieldsObject = exchange.getIn().getHeader(QueueServiceConstants.MESSAGE_UPDATE_FIELDS);
    if (fieldsObject instanceof EnumSet) {
        @SuppressWarnings("unchecked") EnumSet<MessageUpdateFields> theFields = (EnumSet<MessageUpdateFields>) fieldsObject;
        fields = theFields;
    } else if (fieldsObject instanceof MessageUpdateFields) {
        fields = EnumSet.of((MessageUpdateFields) fieldsObject);
    }
    client.updateMessage(message, getConfiguration().getMessageVisibilityDelay(), fields, opts.getRequestOpts(), opts.getOpContext());
}
Also used : EnumSet(java.util.EnumSet) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) MessageUpdateFields(com.microsoft.azure.storage.queue.MessageUpdateFields) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Aggregations

CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)20 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)8 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)7 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)7 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)4 JndiRegistry (org.apache.camel.impl.JndiRegistry)3 Test (org.junit.Test)3 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)2 QueueMessage (com.microsoft.tooling.msservices.model.storage.QueueMessage)2 MessageUpdateFields (com.microsoft.azure.storage.queue.MessageUpdateFields)1 QueueListingDetails (com.microsoft.azure.storage.queue.QueueListingDetails)1 Queue (com.microsoft.tooling.msservices.model.storage.Queue)1 URI (java.net.URI)1 EnumSet (java.util.EnumSet)1