Search in sources :

Example 1 with Message

use of org.apache.qpid.amqp_1_0.client.Message in project storm by apache.

the class StringEventDataScheme method deserialize.

@Override
public List<Object> deserialize(Message message) {
    final List<Object> fieldContents = new ArrayList<Object>();
    for (Section section : message.getPayload()) {
        if (section instanceof Data) {
            Data data = (Data) section;
            fieldContents.add(new String(data.getValue().getArray()));
        } else if (section instanceof AmqpValue) {
            AmqpValue amqpValue = (AmqpValue) section;
            fieldContents.add(amqpValue.getValue().toString());
        }
    }
    return fieldContents;
}
Also used : ArrayList(java.util.ArrayList) Data(org.apache.qpid.amqp_1_0.type.messaging.Data) Section(org.apache.qpid.amqp_1_0.type.Section) AmqpValue(org.apache.qpid.amqp_1_0.type.messaging.AmqpValue)

Example 2 with Message

use of org.apache.qpid.amqp_1_0.client.Message in project storm by apache.

the class BinaryEventDataScheme method deserialize.

@Override
public List<Object> deserialize(Message message) {
    final List<Object> fieldContents = new ArrayList<Object>();
    Map metaDataMap = new HashMap();
    byte[] messageData = new byte[0];
    for (Section section : message.getPayload()) {
        if (section instanceof Data) {
            Data data = (Data) section;
            messageData = data.getValue().getArray();
        } else if (section instanceof ApplicationProperties) {
            final ApplicationProperties applicationProperties = (ApplicationProperties) section;
            metaDataMap = applicationProperties.getValue();
        }
    }
    fieldContents.add(messageData);
    fieldContents.add(metaDataMap);
    return fieldContents;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationProperties(org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties) Data(org.apache.qpid.amqp_1_0.type.messaging.Data) Map(java.util.Map) HashMap(java.util.HashMap) Section(org.apache.qpid.amqp_1_0.type.Section)

Example 3 with Message

use of org.apache.qpid.amqp_1_0.client.Message in project storm by apache.

the class EventDataScheme method deserialize.

@Override
public List<Object> deserialize(Message message) {
    final List<Object> fieldContents = new ArrayList<Object>();
    Map metaDataMap = new HashMap();
    String messageData = "";
    for (Section section : message.getPayload()) {
        if (section instanceof Data) {
            Data data = (Data) section;
            messageData = new String(data.getValue().getArray());
        } else if (section instanceof AmqpValue) {
            AmqpValue amqpValue = (AmqpValue) section;
            messageData = amqpValue.getValue().toString();
        } else if (section instanceof ApplicationProperties) {
            final ApplicationProperties applicationProperties = (ApplicationProperties) section;
            metaDataMap = applicationProperties.getValue();
        }
    }
    fieldContents.add(messageData);
    fieldContents.add(metaDataMap);
    return fieldContents;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationProperties(org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties) Data(org.apache.qpid.amqp_1_0.type.messaging.Data) Map(java.util.Map) HashMap(java.util.HashMap) Section(org.apache.qpid.amqp_1_0.type.Section) AmqpValue(org.apache.qpid.amqp_1_0.type.messaging.AmqpValue)

Example 4 with Message

use of org.apache.qpid.amqp_1_0.client.Message in project storm by apache.

the class EventHubReceiverImpl method receive.

@Override
public EventData receive(long timeoutInMilliseconds) {
    long start = System.currentTimeMillis();
    Message message = receiver.receive(timeoutInMilliseconds);
    long end = System.currentTimeMillis();
    long millis = (end - start);
    receiveApiLatencyMean.update(millis);
    receiveApiCallCount.incr();
    if (message == null) {
        /*if(timeoutInMilliseconds > 100 && millis < timeoutInMilliseconds/2) {
        throw new RuntimeException(
            "Restart EventHubSpout due to failure of receiving messages in "
            + millis + " millisecond");
      }*/
        return null;
    }
    receiveMessageCount.incr();
    MessageId messageId = createMessageId(message);
    return EventData.create(message, messageId);
}
Also used : Message(org.apache.qpid.amqp_1_0.client.Message)

Example 5 with Message

use of org.apache.qpid.amqp_1_0.client.Message in project storm by apache.

the class EventHubReceiverImpl method createMessageId.

private MessageId createMessageId(Message message) {
    String offset = null;
    long sequenceNumber = 0;
    for (Section section : message.getPayload()) {
        if (section instanceof MessageAnnotations) {
            MessageAnnotations annotations = (MessageAnnotations) section;
            HashMap annonationMap = (HashMap) annotations.getValue();
            if (annonationMap.containsKey(OffsetKey)) {
                offset = (String) annonationMap.get(OffsetKey);
            }
            if (annonationMap.containsKey(SequenceNumberKey)) {
                sequenceNumber = (Long) annonationMap.get(SequenceNumberKey);
            }
        }
    }
    return MessageId.create(partitionId, offset, sequenceNumber);
}
Also used : HashMap(java.util.HashMap) MessageAnnotations(org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations) Section(org.apache.qpid.amqp_1_0.type.Section)

Aggregations

Section (org.apache.qpid.amqp_1_0.type.Section)5 ArrayList (java.util.ArrayList)4 Data (org.apache.qpid.amqp_1_0.type.messaging.Data)4 HashMap (java.util.HashMap)3 Message (org.apache.qpid.amqp_1_0.client.Message)3 Map (java.util.Map)2 AmqpValue (org.apache.qpid.amqp_1_0.type.messaging.AmqpValue)2 ApplicationProperties (org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties)2 Binary (org.apache.qpid.amqp_1_0.type.Binary)1 MessageAnnotations (org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations)1 EventData (org.apache.storm.eventhubs.spout.EventData)1 MessageId (org.apache.storm.eventhubs.spout.MessageId)1