com.microsoft.azure.storage.queue.CloudQueueMessage Java Examples

The following examples show how to use com.microsoft.azure.storage.queue.CloudQueueMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureStorageQueueOutputWriterTestIT.java    From components with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteSimpleMessage() throws Throwable {
    queue.clear();
    //
    TAzureStorageQueueOutputProperties properties = new TAzureStorageQueueOutputProperties("tests");
    properties = (TAzureStorageQueueOutputProperties) setupConnectionProperties(
            (AzureStorageProvideConnectionProperties) properties);
    properties.setupProperties();
    properties.queueName.setValue(TEST_QUEUE_NAME);
    Writer<?> writer = createWriter(properties);
    writer.open("test-uid");
    for (String m : messages) {
        IndexedRecord entity = new GenericData.Record(properties.schema.schema.getValue());
        entity.put(0, m + "SIMPLE");
        writer.write(entity);
    }
    writer.close();
    queue.downloadAttributes();
    assertEquals(3, queue.getApproximateMessageCount());
    for (CloudQueueMessage msg : queue.retrieveMessages(3)) {
        assertNotNull(msg.getMessageContentAsString());
        assertTrue(msg.getMessageContentAsString().indexOf("SIMPLE") > 0);
    }
}
 
Example #2
Source File: AzureStorageQueueInputReaderTestIT.java    From components with Apache License 2.0 6 votes vote down vote up
public AzureStorageQueueInputReaderTestIT() {
    super("queue-input");
    try {
        //
        queue.clear();
        for (int idx = 0; idx < 50; idx++) {
            queue.addMessage(new CloudQueueMessage("messageContent#" + idx));
        }
        //
        inputProps = new TAzureStorageQueueInputProperties("tests");
        inputProps = (TAzureStorageQueueInputProperties) setupConnectionProperties(
                (AzureStorageProvideConnectionProperties) inputProps);
        inputProps.setupProperties();
        inputProps.queueName.setValue(TEST_QUEUE_NAME);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #3
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartHandleError() {
    try {
        properties.peekMessages.setValue(true);
        properties.dieOnError.setValue(false);

        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());

        reader = (AzureStorageQueueInputReader) source.createReader(getDummyRuntimeContiner());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.peekMessages(anyString(), anyInt()))
                .thenThrow(new StorageException("code", "some storage exception", new RuntimeException()));

        boolean startable = reader.start();
        assertFalse(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #4
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 6 votes vote down vote up
@Test(expected = ComponentException.class)
public void testStartDieOnError() {
    try {
        properties.peekMessages.setValue(true);
        properties.dieOnError.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());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.peekMessages(anyString(), anyInt()))
                .thenThrow(new StorageException("code", "some storage exception", new RuntimeException()));

        boolean startable = reader.start();
        assertFalse(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #5
Source File: AzureStorageClient.java    From azure-kusto-java with MIT License 5 votes vote down vote up
void postMessageToQueue(String queuePath, String content) throws StorageException, URISyntaxException {
    // Ensure
    Ensure.stringIsNotBlank(queuePath, "queuePath");
    Ensure.stringIsNotBlank(content, "content");

    CloudQueue queue = new CloudQueue(new URI(queuePath));
    CloudQueueMessage queueMessage = new CloudQueueMessage(content);
    queue.addMessage(queueMessage);
}
 
Example #6
Source File: AzureStorageQueueInputLoopReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvanceAsAdvancable() {
    try {

        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());

        reader = (AzureStorageQueueInputLoopReader) source.createReader(getDummyRuntimeContiner());
        reader.queueService = queueService; // inject mocked service

        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);
            }
        });
        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                return null;
            }
        }).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));

        boolean startable = reader.start();
        assertTrue(startable);
        boolean advancable = reader.advance();
        assertTrue(advancable);

    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #7
Source File: AzureStorageQueueInputLoopReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartAsStartable() {
    try {

        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());

        reader = (AzureStorageQueueInputLoopReader) source.createReader(getDummyRuntimeContiner());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.retrieveMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                return null;
            }
        }).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));

        boolean startable = reader.start();
        assertTrue(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #8
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetReturnValues() {
    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());
        reader.queueService = queueService; // inject mocked service

        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.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertTrue(startable);
        while (reader.advance()) {
            // read all messages to init the returned values at the end
        }
        Map<String, Object> returnedValues = reader.getReturnValues();
        assertNotNull(returnedValues);
        assertEquals("some-queue-name", returnedValues.get(AzureStorageQueueDefinition.RETURN_QUEUE_NAME));
        assertEquals(3, returnedValues.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #9
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test(expected = NoSuchElementException.class)
public void testGetCurrentWhenNotAdvancable() {
    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());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertTrue(startable);
        assertNotNull(reader.getCurrent());
        boolean advancable = reader.advance();
        assertFalse(advancable);
        reader.getCurrent(); // should throw NoSuchElementException

    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #10
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@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());
        reader.queueService = queueService; // inject mocked service

        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);
        reader.getCurrent(); // should throw NoSuchElementException

    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #11
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCurrent() {
    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());
        reader.queueService = queueService; // inject mocked service

        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.peekMessages(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++;
        } while (reader.advance());

    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #12
Source File: GetAzureQueueStorage.java    From nifi with Apache License 2.0 5 votes vote down vote up
private List<CloudQueueMessage> toList(Iterable<CloudQueueMessage> iterable) {
    if (iterable instanceof List) {
        return (List<CloudQueueMessage>) iterable;
    }

    final ArrayList<CloudQueueMessage> list = new ArrayList<>();
    if (iterable != null) {
        for(CloudQueueMessage message : iterable) {
            list.add(message);
        }
    }

    return list;
}
 
Example #13
Source File: PutAzureQueueStorage.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    final long startNanos = System.nanoTime();

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    session.exportTo(flowFile, baos);
    final String flowFileContent = baos.toString();

    CloudQueueMessage message = new CloudQueueMessage(flowFileContent);
    CloudQueueClient cloudQueueClient;
    CloudQueue cloudQueue;

    final int ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.SECONDS).intValue();
    final int delay = context.getProperty(VISIBILITY_DELAY).asTimePeriod(TimeUnit.SECONDS).intValue();
    final String queue = context.getProperty(QUEUE).evaluateAttributeExpressions(flowFile).getValue().toLowerCase();

    try {
        cloudQueueClient = createCloudQueueClient(context, flowFile);
        cloudQueue = cloudQueueClient.getQueueReference(queue);

        final OperationContext operationContext = new OperationContext();
        AzureStorageUtils.setProxy(operationContext, context);

        cloudQueue.addMessage(message, ttl, delay, null, operationContext);
    } catch (URISyntaxException | StorageException e) {
        getLogger().error("Failed to write the message to Azure Queue Storage due to {}", new Object[]{e});
        flowFile = session.penalize(flowFile);
        session.transfer(flowFile, REL_FAILURE);
        return;
    }

    session.transfer(flowFile, REL_SUCCESS);
    final long transmissionMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
    session.getProvenanceReporter().send(flowFile, cloudQueue.getUri().toString(), transmissionMillis);
}
 
Example #14
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvanceWhenNonStartble() {
    try {
        properties.peekMessages.setValue(true);
        properties.deleteMessages.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());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });

        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                throw new StorageException("code", "message-1 can't be deleted", new RuntimeException());
            }
        }).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));

        boolean startable = reader.start();
        assertFalse(startable);
        boolean advancable = reader.advance();
        assertFalse(advancable);

    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #15
Source File: AbstractAzureQueueStorageIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected int getMessageCount() throws Exception {
    Iterator<CloudQueueMessage> retrievedMessages = cloudQueue.retrieveMessages(10, 1, null, null).iterator();
    int count = 0;

    while (retrievedMessages.hasNext()) {
        retrievedMessages.next();
        count++;
    }

    return count;
}
 
Example #16
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvanceAsAdvancable() {
    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());
        reader.queueService = queueService; // inject mocked service

        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.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertTrue(startable);
        boolean advancable = reader.advance();
        assertTrue(advancable);

    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #17
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartPeekHandleDeletionError() {
    try {
        properties.peekMessages.setValue(true);
        properties.deleteMessages.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());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });

        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                throw new StorageException("code", "message-1 can't be deleted", new RuntimeException());
            }
        }).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));

        boolean startable = reader.start();
        assertTrue(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #18
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartPeekAndDeleteMessage() {
    try {
        properties.peekMessages.setValue(true);
        properties.deleteMessages.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());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });

        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                return null;
            }
        }).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));

        boolean startable = reader.start();
        assertTrue(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #19
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@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());
        reader.queueService = queueService; // inject mocked service

        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());
    }
}
 
Example #20
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartRetrieveMessageAsStartable() {
    try {
        properties.peekMessages.setValue(false);

        AzureStorageQueueSource source = new AzureStorageQueueSource();
        ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
        assertNotNull(vr);
        assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());

        reader = (AzureStorageQueueInputReader) source.createReader(getDummyRuntimeContiner());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.retrieveMessages(anyString(), anyInt(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertTrue(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #21
Source File: AzureStorageQueueInputReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartPeekAsStartable() {
    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());
        reader.queueService = queueService; // inject mocked service

        final List<CloudQueueMessage> messages = new ArrayList<>();
        messages.add(new CloudQueueMessage("message-1"));
        when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {

            @Override
            public Iterator<CloudQueueMessage> iterator() {
                return new DummyCloudQueueMessageIterator(messages);
            }
        });
        boolean startable = reader.start();
        assertTrue(startable);
    } catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
        fail("sould not throw " + e.getMessage());
    }
}
 
Example #22
Source File: AzureStorageQueueService.java    From components with Apache License 2.0 5 votes vote down vote up
public void deleteMessage(String queueName, CloudQueueMessage message)
        throws InvalidKeyException, URISyntaxException, StorageException {

    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    queueRef.deleteMessage(message, null, AzureStorageUtils.getTalendOperationContext());
}
 
Example #23
Source File: AzureStorageQueueService.java    From components with Apache License 2.0 5 votes vote down vote up
public Iterable<CloudQueueMessage> retrieveMessages(String queueName, int numberOfMessages, int visibilityTimeoutInSeconds)
        throws InvalidKeyException, URISyntaxException, StorageException {

    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.retrieveMessages(numberOfMessages, visibilityTimeoutInSeconds, null, AzureStorageUtils.getTalendOperationContext());
}
 
Example #24
Source File: AzureStorageQueueService.java    From components with Apache License 2.0 5 votes vote down vote up
public Iterable<CloudQueueMessage> peekMessages(String queueName, int numberOfMessages)
        throws InvalidKeyException, URISyntaxException, StorageException {

    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.peekMessages(numberOfMessages, null, AzureStorageUtils.getTalendOperationContext());
}
 
Example #25
Source File: AzureQueueResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Path("/queue/read")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String retrieveMessage() throws Exception {
    CloudQueueMessage message = producerTemplate.requestBody(
            "azure-queue://devstoreaccount1/" + QUEUE_NAME
                    + "?operation=retrieveMessage&azureQueueClient=#azureQueueClient&validateClientURI=false",
            null, CloudQueueMessage.class);
    return message.getMessageContentAsString();
}
 
Example #26
Source File: QueueMessage.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * @param msg
 * @param timeToLiveInSeconds
 * @param initialVisibilityDelayInSeconds
 */
public QueueMessage(CloudQueueMessage msg, int timeToLiveInSeconds, int initialVisibilityDelayInSeconds) {
    super();
    this.msg = msg;
    this.timeToLiveInSeconds = timeToLiveInSeconds;
    this.initialVisibilityDelayInSeconds = initialVisibilityDelayInSeconds;
}
 
Example #27
Source File: AzureStorageQueueWriter.java    From components with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Object object) throws IOException {
    String content;
    if (object == null)
        return;
    cleanWrites();
    result.totalCount++;
    if (writeSchema == null) {
        writeSchema = ((IndexedRecord) object).getSchema();
    }
    GenericIndexedRecordConverter factory = new GenericIndexedRecordConverter();
    factory.setSchema(writeSchema);
    IndexedRecord inputRecord = factory.convertToAvro((IndexedRecord) object);
    Field msgContent = writeSchema.getField(AzureStorageQueueProperties.FIELD_MESSAGE_CONTENT);
    int ttl = props.timeToLiveInSeconds.getValue();
    int visibility = props.initialVisibilityDelayInSeconds.getValue();

    if (msgContent == null) {
        LOGGER.error(i18nMessages.getMessage("error.VacantMessage"));
        if (props.dieOnError.getValue()) {
            throw new ComponentException(new Exception(i18nMessages.getMessage("error.VacantMessage")));
        }
    } else {
        content = (String) inputRecord.get(msgContent.pos());
        messagesBuffer.add(new QueueMessage(new CloudQueueMessage(content), ttl, visibility));
    }

    if (messagesBuffer.size() >= MAX_MSG_TO_ENQUEUE) {
        sendParallelMessages();
    }
}
 
Example #28
Source File: GetAzureQueueStorageIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws StorageException {
    cloudQueue.addMessage(new CloudQueueMessage("Dummy Message 1"), 604800, 0, null, null);
    cloudQueue.addMessage(new CloudQueueMessage("Dummy Message 2"), 604800, 0, null, null);
    cloudQueue.addMessage(new CloudQueueMessage("Dummy Message 3"), 604800, 0, null, null);
}
 
Example #29
Source File: AzureIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@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.close();
    }
}
 
Example #30
Source File: DummyCloudQueueMessageIterator.java    From components with Apache License 2.0 4 votes vote down vote up
@Override
public CloudQueueMessage next() {
    return it.next();
}