use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueOutputWriterTestIT method testWriteTTLMessage.
@Test
public void testWriteTTLMessage() throws Throwable {
queue.clear();
//
TAzureStorageQueueOutputProperties properties = new TAzureStorageQueueOutputProperties("tests");
properties = (TAzureStorageQueueOutputProperties) setupConnectionProperties((AzureStorageProvideConnectionProperties) properties);
properties.setupProperties();
properties.queueName.setValue(TEST_QUEUE_NAME);
properties.timeToLiveInSeconds.setValue(5);
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 + "TTL");
writer.write(entity);
}
writer.close();
int msgCount = 0;
for (CloudQueueMessage msg : queue.retrieveMessages(30)) {
msgCount++;
assertNotNull(msg.getMessageContentAsString());
assertTrue(msg.getMessageContentAsString().indexOf("TTL") > 0);
}
assertEquals(3, msgCount);
Thread.sleep(5000);
msgCount = 0;
for (CloudQueueMessage msg : queue.retrieveMessages(30)) {
msgCount++;
assertNotNull(msg.getMessageContentAsString());
}
assertEquals(0, msgCount);
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueOutputWriterTestIT method testWriteDelayedMessage.
@Test
public void testWriteDelayedMessage() throws Throwable {
queue.clear();
//
TAzureStorageQueueOutputProperties properties = new TAzureStorageQueueOutputProperties("tests");
properties = (TAzureStorageQueueOutputProperties) setupConnectionProperties((AzureStorageProvideConnectionProperties) properties);
properties.setupProperties();
properties.queueName.setValue(TEST_QUEUE_NAME);
properties.initialVisibilityDelayInSeconds.setValue(5);
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 + "DLY");
writer.write(entity);
}
writer.close();
int msgCount = 0;
for (CloudQueueMessage msg : queue.retrieveMessages(30)) {
// we shoud not be here ...
msgCount++;
assertNotNull(msg.getMessageContentAsString());
assertTrue(msg.getMessageContentAsString().indexOf("DLY") > 0);
}
assertEquals(0, msgCount);
Thread.sleep(5000);
msgCount = 0;
for (CloudQueueMessage msg : queue.retrieveMessages(30)) {
msgCount++;
assertNotNull(msg.getMessageContentAsString());
assertTrue(msg.getMessageContentAsString().indexOf("DLY") > 0);
}
assertEquals(3, msgCount);
queue.downloadAttributes();
assertEquals(3, queue.getApproximateMessageCount());
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getQueueMessages.
@NotNull
public List<QueueMessage> getQueueMessages(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
List<QueueMessage> qmList = new ArrayList<QueueMessage>();
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
for (CloudQueueMessage cqm : cloudQueue.peekMessages(32)) {
String id = Strings.nullToEmpty(cqm.getId());
String content = Strings.nullToEmpty(cqm.getMessageContentAsString());
Calendar insertionTime = new GregorianCalendar();
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
Calendar expirationTime = new GregorianCalendar();
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
int dequeueCount = cqm.getDequeueCount();
qmList.add(new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount));
}
return qmList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Queue Message list", t);
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createQueueMessage.
public void createQueueMessage(@NotNull StorageAccount storageAccount, @NotNull QueueMessage queueMessage, int timeToLiveInSeconds) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queueMessage.getQueueName());
cloudQueue.addMessage(new CloudQueueMessage(queueMessage.getContent()), timeToLiveInSeconds, 0, null, null);
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Queue Message", t);
}
}
Aggregations