Search in sources :

Example 1 with EventData

use of org.apache.storm.eventhubs.spout.EventData in project storm by apache.

the class TransactionalTridentEventHubEmitter method emitPartitionBatchNew.

@Override
public Map emitPartitionBatchNew(TransactionAttempt attempt, TridentCollector collector, Partition partition, Map meta) {
    ITridentPartitionManager pm = getOrCreatePartitionManager(partition);
    String offset = Constants.DefaultStartingOffset;
    if (meta != null && meta.containsKey("nextOffset")) {
        offset = (String) meta.get("nextOffset");
    }
    //logger.info("emit for partition " + partition.getId() + ", offset=" + offset);
    String nextOffset = offset;
    List<EventData> listEvents = pm.receiveBatch(offset, batchSize);
    for (EventData ed : listEvents) {
        //update nextOffset;
        nextOffset = ed.getMessageId().getOffset();
        List<Object> tuples = spoutConfig.getEventDataScheme().deserialize(ed.getMessage());
        collector.emit(tuples);
    }
    //logger.info("emitted new batches: " + listEvents.size());
    Map newMeta = new HashMap();
    newMeta.put("offset", offset);
    newMeta.put("nextOffset", nextOffset);
    newMeta.put("count", "" + listEvents.size());
    return newMeta;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) EventData(org.apache.storm.eventhubs.spout.EventData)

Example 2 with EventData

use of org.apache.storm.eventhubs.spout.EventData in project storm by apache.

the class TransactionalTridentEventHubEmitter method emitPartitionBatch.

@Override
public void emitPartitionBatch(TransactionAttempt attempt, TridentCollector collector, Partition partition, Map meta) {
    String offset = (String) meta.get("offset");
    int count = Integer.parseInt((String) meta.get("count"));
    logger.info("re-emit for partition " + partition.getId() + ", offset=" + offset + ", count=" + count);
    ITridentPartitionManager pm = getOrCreatePartitionManager(partition);
    List<EventData> listEvents = pm.receiveBatch(offset, count);
    if (listEvents.size() != count) {
        logger.error("failed to refetch eventhub messages, new count=" + listEvents.size());
        return;
    }
    for (EventData ed : listEvents) {
        List<Object> tuples = spoutConfig.getEventDataScheme().deserialize(ed.getMessage());
        collector.emit(tuples);
    }
}
Also used : EventData(org.apache.storm.eventhubs.spout.EventData)

Example 3 with EventData

use of org.apache.storm.eventhubs.spout.EventData in project storm by apache.

the class EventHubReceiverMock method receive.

@Override
public EventData receive(long timeoutInMilliseconds) {
    if (isPaused) {
        return null;
    }
    currentOffset++;
    List<Section> body = new ArrayList<Section>();
    //the body of the message is "message" + currentOffset, e.g. "message123"
    body.add(new Data(new Binary(("message" + currentOffset).getBytes())));
    Message m = new Message(body);
    MessageId mid = new MessageId(partitionId, "" + currentOffset, currentOffset);
    EventData ed = new EventData(m, mid);
    return ed;
}
Also used : Message(org.apache.qpid.amqp_1_0.client.Message) ArrayList(java.util.ArrayList) Data(org.apache.qpid.amqp_1_0.type.messaging.Data) EventData(org.apache.storm.eventhubs.spout.EventData) Binary(org.apache.qpid.amqp_1_0.type.Binary) Section(org.apache.qpid.amqp_1_0.type.Section) EventData(org.apache.storm.eventhubs.spout.EventData) MessageId(org.apache.storm.eventhubs.spout.MessageId)

Example 4 with EventData

use of org.apache.storm.eventhubs.spout.EventData in project storm by apache.

the class PartitionManagerCallerMock method execute.

/**
   * Execute a sequence of calls to Partition Manager.
   * 
   * @param callSequence: is represented as a string of commands, 
   * e.g. "r,r,r,r,a1,f2,...". The commands are:
   * r[N]: receive() called N times
   * aX: ack(X)
   * fY: fail(Y)
   * 
   * @return the sequence of messages the receive call returns
   */
public String execute(String callSequence) {
    String[] cmds = callSequence.split(",");
    StringBuilder ret = new StringBuilder();
    for (String cmd : cmds) {
        if (cmd.startsWith("r")) {
            int count = 1;
            if (cmd.length() > 1) {
                count = Integer.parseInt(cmd.substring(1));
            }
            for (int i = 0; i < count; ++i) {
                EventData ed = pm.receive();
                if (ed == null) {
                    ret.append("null,");
                } else {
                    ret.append(ed.getMessageId().getOffset());
                    ret.append(",");
                }
            }
        } else if (cmd.startsWith("a")) {
            pm.ack(cmd.substring(1));
        } else if (cmd.startsWith("f")) {
            pm.fail(cmd.substring(1));
        }
    }
    if (ret.length() > 0) {
        ret.setLength(ret.length() - 1);
    }
    return ret.toString();
}
Also used : EventData(org.apache.storm.eventhubs.spout.EventData)

Aggregations

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