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