use of com.microsoft.azure.storage.queue.CloudQueueMessage in project camel by apache.
the class QueueServiceProducer method addMessage.
private void addMessage(Exchange exchange) throws Exception {
LOG.trace("Putting the message into the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange);
CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
Boolean queueCreated = exchange.getIn().getHeader(QueueServiceConstants.QUEUE_CREATED, Boolean.class);
if (Boolean.TRUE != queueCreated) {
doCreateQueue(client, opts, exchange);
}
CloudQueueMessage message = getCloudQueueMessage(exchange);
client.addMessage(message, getConfiguration().getMessageTimeToLive(), getConfiguration().getMessageVisibilityDelay(), opts.getRequestOpts(), opts.getOpContext());
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project camel by apache.
the class QueueServiceProducer method peekMessage.
private void peekMessage(Exchange exchange) throws Exception {
CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
CloudQueueMessage message = client.peekMessage(opts.getRequestOpts(), opts.getOpContext());
ExchangeUtil.getMessageForResponse(exchange).setBody(message);
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputReaderTest method testGetReturnValues.
@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());
// 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.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());
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputReaderTest method testAdvanceAsAdvancable.
@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());
// 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.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());
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputReaderTest method testStartHandleError.
@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());
// inject mocked service
reader.queueService = queueService;
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());
}
}
Aggregations