Search in sources :

Example 1 with GenericIndexedRecordConverter

use of org.talend.components.common.runtime.GenericIndexedRecordConverter 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)

Aggregations

StorageException (com.microsoft.azure.storage.StorageException)1 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 InvalidKeyException (java.security.InvalidKeyException)1 Field (org.apache.avro.Schema.Field)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 ComponentException (org.talend.components.api.exception.ComponentException)1 GenericIndexedRecordConverter (org.talend.components.common.runtime.GenericIndexedRecordConverter)1