Search in sources :

Example 21 with CloudQueue

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

the class QueueServiceProducer method deleteQueue.

private void deleteQueue(Exchange exchange) throws Exception {
    LOG.trace("Deleting the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange);
    CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
    QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
    client.delete(opts.getRequestOpts(), opts.getOpContext());
}
Also used : CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 22 with CloudQueue

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

the class QueueServiceUtil method retrieveMessage.

public static void retrieveMessage(Exchange exchange, QueueServiceConfiguration cfg) throws Exception {
    CloudQueue client = createQueueClient(cfg);
    QueueServiceRequestOptions opts = getRequestOptions(exchange);
    CloudQueueMessage message = client.retrieveMessage(cfg.getMessageVisibilityDelay(), opts.getRequestOpts(), opts.getOpContext());
    ExchangeUtil.getMessageForResponse(exchange).setBody(message);
}
Also used : CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 23 with CloudQueue

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

the class QueueServiceComponentConfigurationTest method testCreateEndpointWithMinConfigForClientOnly.

@Test
public void testCreateEndpointWithMinConfigForClientOnly() throws Exception {
    CloudQueue client = new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue/messages"), 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/testqueue?azureQueueClient=#azureQueueClient");
    doTestCreateEndpointWithMinConfig(endpoint, true);
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Test(org.junit.Test)

Example 24 with CloudQueue

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

the class QueueServiceUtilTest method testGetConfiguredClient.

@Test
public void testGetConfiguredClient() throws Exception {
    CloudQueue client = new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue/messages"), 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/testqueue?azureQueueClient=#azureQueueClient");
    assertSame(client, QueueServiceUtil.getConfiguredClient(endpoint.getConfiguration()));
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Test(org.junit.Test)

Example 25 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project wildfly-camel by wildfly-extras.

the class AzureIntegrationTest method testAppendQueue.

@Test
public void testAppendQueue() throws Exception {
    StorageCredentials creds = getStorageCredentials("camelqueue", System.getenv(AZURE_STORAGE_QUEUE));
    Assume.assumeNotNull("Credentials not null", creds);
    OperationContext.setLoggingEnabledByDefault(true);
    CamelContext camelctx = createCamelContext(creds);
    camelctx.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:createQueue").to("azure-queue://camelqueue/queue1?credentials=#creds&operation=createQueue");
            from("direct:listQueues").to("azure-queue://camelqueue?credentials=#creds&operation=listQueues");
            from("direct:deleteQueue").to("azure-queue://camelqueue/queue1?credentials=#creds&operation=deleteQueue");
            from("direct:addMessage").to("azure-queue://camelqueue/queue1?credentials=#creds&operation=addMessage");
            from("direct:retrieveMessage").to("azure-queue://camelqueue/queue1?credentials=#creds&operation=retrieveMessage");
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Iterator<?> it = producer.requestBody("direct:listQueues", null, Iterable.class).iterator();
        Assert.assertFalse("No more queues", it.hasNext());
        producer.sendBody("direct:addMessage", "SomeMsg");
        it = producer.requestBody("direct:listQueues", null, Iterable.class).iterator();
        Assert.assertTrue("Has queues", it.hasNext());
        CloudQueue queue = (CloudQueue) it.next();
        Assert.assertEquals("queue1", queue.getName());
        Assert.assertFalse("No more queues", it.hasNext());
        try {
            CloudQueueMessage msg = producer.requestBody("direct:retrieveMessage", null, CloudQueueMessage.class);
            Assert.assertNotNull("Retrieve a message", msg);
            Assert.assertEquals("SomeMsg", msg.getMessageContentAsString());
        } finally {
            queue.delete();
        }
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) StorageCredentials(com.microsoft.azure.storage.StorageCredentials) RouteBuilder(org.apache.camel.builder.RouteBuilder) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Test(org.junit.Test)

Aggregations

CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)37 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)14 Test (org.junit.Test)13 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)9 IOException (java.io.IOException)9 URISyntaxException (java.net.URISyntaxException)9 InvalidKeyException (java.security.InvalidKeyException)9 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)9 AzureBaseTest (org.talend.components.azurestorage.AzureBaseTest)9 ValidationResult (org.talend.daikon.properties.ValidationResult)9 StorageException (com.microsoft.azure.storage.StorageException)7 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)7 URI (java.net.URI)7 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)4 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)3 JndiRegistry (org.apache.camel.impl.JndiRegistry)3 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