Search in sources :

Example 16 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.

the class AzureStorageQueueWriter method write.

@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();
    }
}
Also used : Field(org.apache.avro.Schema.Field) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericIndexedRecordConverter(org.talend.components.common.runtime.GenericIndexedRecordConverter) ComponentException(org.talend.components.api.exception.ComponentException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Example 17 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method dequeueFirstQueueMessage.

@NotNull
public QueueMessage dequeueFirstQueueMessage(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        String queueName = queue.getName();
        CloudQueue cloudQueue = client.getQueueReference(queueName);
        CloudQueueMessage cqm = cloudQueue.retrieveMessage();
        String id = "";
        String content = "";
        Calendar insertionTime = new GregorianCalendar();
        Calendar expirationTime = new GregorianCalendar();
        int dequeueCount = 0;
        if (cqm != null) {
            id = Strings.nullToEmpty(cqm.getId());
            content = Strings.nullToEmpty(cqm.getMessageContentAsString());
            if (cqm.getInsertionTime() != null) {
                insertionTime.setTime(cqm.getInsertionTime());
            }
            if (cqm.getExpirationTime() != null) {
                expirationTime.setTime(cqm.getExpirationTime());
            }
            dequeueCount = cqm.getDequeueCount();
        }
        QueueMessage queueMessage = new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount);
        if (cqm != null) {
            cloudQueue.deleteMessage(cqm);
        }
        return queueMessage;
    } catch (Throwable t) {
        throw new AzureCmdException("Error dequeuing the first Queue Message", 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 18 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project camel by apache.

the class QueueServiceProducer method updateMessage.

private void updateMessage(Exchange exchange) throws Exception {
    CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
    QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
    CloudQueueMessage message = getCloudQueueMessage(exchange);
    LOG.trace("Updating the message in the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange);
    EnumSet<MessageUpdateFields> fields = null;
    Object fieldsObject = exchange.getIn().getHeader(QueueServiceConstants.MESSAGE_UPDATE_FIELDS);
    if (fieldsObject instanceof EnumSet) {
        @SuppressWarnings("unchecked") EnumSet<MessageUpdateFields> theFields = (EnumSet<MessageUpdateFields>) fieldsObject;
        fields = theFields;
    } else if (fieldsObject instanceof MessageUpdateFields) {
        fields = EnumSet.of((MessageUpdateFields) fieldsObject);
    }
    client.updateMessage(message, getConfiguration().getMessageVisibilityDelay(), fields, opts.getRequestOpts(), opts.getOpContext());
}
Also used : EnumSet(java.util.EnumSet) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) MessageUpdateFields(com.microsoft.azure.storage.queue.MessageUpdateFields) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 19 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project camel by apache.

the class QueueServiceProducer method getCloudQueueMessage.

private CloudQueueMessage getCloudQueueMessage(Exchange exchange) throws Exception {
    Object body = exchange.getIn().getMandatoryBody();
    CloudQueueMessage message = null;
    if (body instanceof CloudQueueMessage) {
        message = (CloudQueueMessage) body;
    } else if (body instanceof String) {
        message = new CloudQueueMessage((String) body);
    }
    if (message == null) {
        throw new IllegalArgumentException("Unsupported queue message type:" + body.getClass().getName());
    }
    return message;
}
Also used : CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage)

Example 20 with CloudQueueMessage

use of com.microsoft.azure.storage.queue.CloudQueueMessage in project camel by apache.

the class QueueServiceProducer method deleteMessage.

private void deleteMessage(Exchange exchange) throws Exception {
    LOG.trace("Deleting the message from the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange);
    CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
    QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
    CloudQueueMessage message = getCloudQueueMessage(exchange);
    client.deleteMessage(message, opts.getRequestOpts(), opts.getOpContext());
}
Also used : 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