Search in sources :

Example 31 with CloudQueueMessage

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);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) TAzureStorageQueueOutputProperties(org.talend.components.azurestorage.queue.tazurestoragequeueoutput.TAzureStorageQueueOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) Test(org.junit.Test)

Example 32 with CloudQueueMessage

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());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) TAzureStorageQueueOutputProperties(org.talend.components.azurestorage.queue.tazurestoragequeueoutput.TAzureStorageQueueOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) Test(org.junit.Test)

Example 33 with CloudQueueMessage

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);
    }
}
Also used : QueueMessage(com.microsoft.tooling.msservices.model.storage.QueueMessage) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 34 with CloudQueueMessage

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);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

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