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);
}
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();
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations