Search in sources :

Example 21 with CloudQueueMessage

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

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

Example 23 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.

the class AzureStorageQueueInputLoopReaderTest method testGetCurrent.

@Test
public void testGetCurrent() {
    try {
        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
        reader = (AzureStorageQueueInputLoopReader) source.createReader(getDummyRuntimeContiner());
        // inject mocked service
        reader.queueService = queueService;
        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        messages.add(new CloudQueueMessage("message-2"));
        messages.add(new CloudQueueMessage("message-3"));
        when(queueService.retrieveMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertTrue(startable);
        int i = 1;
        do {
            IndexedRecord current = reader.getCurrent();
            assertNotNull(current);
            assertNotNull(current.getSchema());
            Field msgField = current.getSchema().getField(TAzureStorageQueueInputProperties.FIELD_MESSAGE_CONTENT);
            assertTrue(current.get(msgField.pos()).equals("message-" + i));
            i++;
            if (i == 3) {
                break;
            }
        } while (reader.advance());
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ValidationResult(org.talend.daikon.properties.ValidationResult) InvalidKeyException(java.security.InvalidKeyException) Field(org.apache.avro.Schema.Field) Iterator(java.util.Iterator) StorageException(com.microsoft.azure.storage.StorageException) AzureBaseTest(org.talend.components.azurestorage.AzureBaseTest) Test(org.junit.Test)

Example 24 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.

the class AzureStorageQueueInputReaderTest method testGetCurrentWhenNotStartable.

@Test(expected = NoSuchElementException.class)
public void testGetCurrentWhenNotStartable() {
    try {
        properties.peekMessages.setValue(true);
        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
        reader = (AzureStorageQueueInputReader) source.createReader(getDummyRuntimeContiner());
        // inject mocked service
        reader.queueService = queueService;
        final List<CloudQueueMessage> messages = new ArrayList<>();
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertFalse(startable);
        // should throw NoSuchElementException
        reader.getCurrent();
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
Also used : CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ValidationResult(org.talend.daikon.properties.ValidationResult) InvalidKeyException(java.security.InvalidKeyException) Iterator(java.util.Iterator) StorageException(com.microsoft.azure.storage.StorageException) AzureBaseTest(org.talend.components.azurestorage.AzureBaseTest) Test(org.junit.Test)

Example 25 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.

the class AzureStorageQueueInputReaderTest method testStartPeekAsNonStartable.

@Test
public void testStartPeekAsNonStartable() {
    try {
        properties.peekMessages.setValue(true);
        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
        reader = (AzureStorageQueueInputReader) source.createReader(getDummyRuntimeContiner());
        // inject mocked service
        reader.queueService = queueService;
        final List<CloudQueueMessage> messages = new ArrayList<>();
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertFalse(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
Also used : CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ValidationResult(org.talend.daikon.properties.ValidationResult) InvalidKeyException(java.security.InvalidKeyException) Iterator(java.util.Iterator) StorageException(com.microsoft.azure.storage.StorageException) AzureBaseTest(org.talend.components.azurestorage.AzureBaseTest) Test(org.junit.Test)

Aggregations

CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)34 Test (org.junit.Test)24 StorageException (com.microsoft.azure.storage.StorageException)21 IOException (java.io.IOException)21 URISyntaxException (java.net.URISyntaxException)21 InvalidKeyException (java.security.InvalidKeyException)21 ArrayList (java.util.ArrayList)20 AzureBaseTest (org.talend.components.azurestorage.AzureBaseTest)20 ValidationResult (org.talend.daikon.properties.ValidationResult)20 Iterator (java.util.Iterator)18 CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 IndexedRecord (org.apache.avro.generic.IndexedRecord)6 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)3 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)3 Field (org.apache.avro.Schema.Field)3 TAzureStorageQueueOutputProperties (org.talend.components.azurestorage.queue.tazurestoragequeueoutput.TAzureStorageQueueOutputProperties)3 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)2 QueueMessage (com.microsoft.tooling.msservices.model.storage.QueueMessage)2 Matchers.anyString (org.mockito.Matchers.anyString)2