Search in sources :

Example 6 with CloudQueue

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

the class QueueServiceUtilTest method testGetConfiguredClientUriMismatch.

@Test
public void testGetConfiguredClientUriMismatch() throws Exception {
    CloudQueue client = new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue"), newAccountKeyCredentials());
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("azureQueueClient", client);
    QueueServiceComponent component = new QueueServiceComponent(context);
    QueueServiceEndpoint endpoint = (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue2?azureQueueClient=#azureQueueClient");
    try {
        QueueServiceUtil.getConfiguredClient(endpoint.getConfiguration());
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("Invalid Client URI", ex.getMessage());
    }
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Test(org.junit.Test)

Example 7 with CloudQueue

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

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

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

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

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