当前位置: 首页>>代码示例>>Java>>正文


Java IncomingMessageEnvelope.getMessage方法代码示例

本文整理汇总了Java中org.apache.samza.system.IncomingMessageEnvelope.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java IncomingMessageEnvelope.getMessage方法的具体用法?Java IncomingMessageEnvelope.getMessage怎么用?Java IncomingMessageEnvelope.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.samza.system.IncomingMessageEnvelope的用法示例。


在下文中一共展示了IncomingMessageEnvelope.getMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
  Map<String, Object> jsonObject = (Map<String, Object>) envelope.getMessage();
  WikipediaFeedEvent event = new WikipediaFeedEvent(jsonObject);

  try {
    Map<String, Object> parsedJsonObject = parse(event.getRawEvent());

    parsedJsonObject.put("channel", event.getChannel());
    parsedJsonObject.put("source", event.getSource());
    parsedJsonObject.put("time", event.getTime());

    collector.send(new OutgoingMessageEnvelope(new SystemStream("kafka", "wikipedia-edits"), parsedJsonObject));
  } catch (Exception e) {
    System.err.println("Unable to parse line: " + event);
  }
}
 
开发者ID:yoloanalytics,项目名称:bigdata-swamp,代码行数:19,代码来源:WikipediaParserStreamTask.java

示例2: getUnreadMessages

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
/**
 * returns all unread messages of a specific type, after an iterator on the stream
 *
 * @param iterator the iterator pointing to an offset in the coordinator stream. All unread messages after this iterator are returned
 * @param type     the type of the messages to be returned
 * @return a set of unread messages of a given type, after a given iterator
 */
public Set<CoordinatorStreamMessage> getUnreadMessages(SystemStreamPartitionIterator iterator, String type) {
  LinkedHashSet<CoordinatorStreamMessage> messages = new LinkedHashSet<CoordinatorStreamMessage>();
  while (iterator.hasNext()) {
    IncomingMessageEnvelope envelope = iterator.next();
    Object[] keyArray = keySerde.fromBytes((byte[]) envelope.getKey()).toArray();
    Map<String, Object> valueMap = null;
    if (envelope.getMessage() != null) {
      valueMap = messageSerde.fromBytes((byte[]) envelope.getMessage());
    }
    CoordinatorStreamMessage coordinatorStreamMessage = new CoordinatorStreamMessage(keyArray, valueMap);
    if (type == null || type.equals(coordinatorStreamMessage.getType())) {
      messages.add(coordinatorStreamMessage);
    }
  }
  return messages;
}
 
开发者ID:apache,项目名称:samza,代码行数:24,代码来源:CoordinatorStreamSystemConsumer.java

示例3: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
/**
 * Passes the incoming message envelopes along to the {@link InputOperatorImpl} node
 * for the input {@link SystemStream}.
 * <p>
 * From then on, each {@link org.apache.samza.operators.impl.OperatorImpl} propagates its transformed output to
 * its chained {@link org.apache.samza.operators.impl.OperatorImpl}s itself.
 *
 * @param ime incoming message envelope to process
 * @param collector the collector to send messages with
 * @param coordinator the coordinator to request commits or shutdown
 */
@Override
public final void process(IncomingMessageEnvelope ime, MessageCollector collector, TaskCoordinator coordinator) {
  SystemStream systemStream = ime.getSystemStreamPartition().getSystemStream();
  InputOperatorImpl inputOpImpl = operatorImplGraph.getInputOperator(systemStream);
  if (inputOpImpl != null) {
    switch (MessageType.of(ime.getMessage())) {
      case USER_MESSAGE:
        inputOpImpl.onMessage(KV.of(ime.getKey(), ime.getMessage()), collector, coordinator);
        break;

      case END_OF_STREAM:
        EndOfStreamMessage eosMessage = (EndOfStreamMessage) ime.getMessage();
        inputOpImpl.aggregateEndOfStream(eosMessage, ime.getSystemStreamPartition(), collector, coordinator);
        break;

      case WATERMARK:
        WatermarkMessage watermarkMessage = (WatermarkMessage) ime.getMessage();
        inputOpImpl.aggregateWatermark(watermarkMessage, ime.getSystemStreamPartition(), collector, coordinator);
        break;
    }
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:34,代码来源:StreamOperatorTask.java

示例4: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) throws Exception {
    String stream = envelope.getSystemStreamPartition().getSystemStream().getStream();
    Object message = envelope.getMessage();

    List<Processor> processors = Processor.getProcessors(stream, this.config, this.context, this.storeManager);
    if (message instanceof Map) {
        for (Processor processor : processors) {
            processor.process((Map<String, Object>) message, collector);
        }
    } else {
        log.warn("This message is not a map class: " + message);
    }
}
 
开发者ID:redBorder,项目名称:rb-samza-streaming,代码行数:15,代码来源:StreamProcessor.java

示例5: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
  Map<String, Object> edit = (Map<String, Object>) envelope.getMessage();
  Map<String, Boolean> flags = (Map<String, Boolean>) edit.get("flags");

  Integer editsAllTime = store.get("count-edits-all-time");
  if (editsAllTime == null) editsAllTime = 0;
  store.put("count-edits-all-time", editsAllTime + 1);

  edits += 1;
  titles.add((String) edit.get("title"));
  byteDiff += (Integer) edit.get("diff-bytes");

  for (Map.Entry<String, Boolean> flag : flags.entrySet()) {
    if (Boolean.TRUE.equals(flag.getValue())) {
      Integer count = counts.get(flag.getKey());

      if (count == null) {
        count = 0;
      }

      count += 1;
      counts.put(flag.getKey(), count);
    }
  }
}
 
开发者ID:yoloanalytics,项目名称:bigdata-swamp,代码行数:28,代码来源:WikipediaStatsStreamTask.java

示例6: readNext

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
public IncomingMessageEnvelope readNext() {
  if (!hasNext()) {
    LOG.warn("Attempting to read more data when there aren't any. ssp=" + systemStreamPartition);
    return null;
  }
  // record the next offset before we read, so when the read fails and we reconnect,
  // we seek to the same offset that we try below
  curSingleFileOffset = curReader.nextOffset();
  IncomingMessageEnvelope messageEnvelope = curReader.readNext();
  // Copy everything except for the offset. Turn the single-file style offset into a multi-file one
  return new IncomingMessageEnvelope(messageEnvelope.getSystemStreamPartition(), getCurOffset(),
    messageEnvelope.getKey(), messageEnvelope.getMessage(), messageEnvelope.getSize());
}
 
开发者ID:apache,项目名称:samza,代码行数:14,代码来源:MultiFileHdfsReader.java

示例7: testRandomRead

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Test
public void testRandomRead() throws Exception {
  SystemStreamPartition ssp = new SystemStreamPartition("hdfs", "testStream", new Partition(0));
  SingleFileHdfsReader reader = new AvroFileHdfsReader(ssp);
  reader.open(AVRO_FILE, "0");
  for (int i = 0;i < NUM_EVENTS / 2; i++) {
    reader.readNext();
  }
  String offset = reader.nextOffset();
  IncomingMessageEnvelope envelope = reader.readNext();
  Assert.assertEquals(offset, envelope.getOffset());

  GenericRecord record1 = (GenericRecord) envelope.getMessage();

  for (int i = 0; i < 5; i++) reader.readNext();

  // seek to the offset within the same reader
  reader.seek(offset);
  Assert.assertEquals(offset, reader.nextOffset());
  envelope = reader.readNext();
  Assert.assertEquals(offset, envelope.getOffset());
  GenericRecord record2 = (GenericRecord) envelope.getMessage();
  Assert.assertEquals(record1, record2);
  reader.close();

  // open a new reader and initialize it with the offset
  reader = new AvroFileHdfsReader(ssp);
  reader.open(AVRO_FILE, offset);
  envelope = reader.readNext();
  Assert.assertEquals(offset, envelope.getOffset());
  GenericRecord record3 = (GenericRecord) envelope.getMessage();
  Assert.assertEquals(record1, record3);
  reader.close();
}
 
开发者ID:apache,项目名称:samza,代码行数:35,代码来源:TestAvroFileHdfsReader.java

示例8: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
  String key = (String) envelope.getKey();
  String value = (String) envelope.getMessage();
  String[] pieces = value.split("-");
  int epoch = Integer.parseInt(pieces[0]);

  int partition = Integer.parseInt(pieces[1].split(" ")[1]);
  Partitions partitions = loadPartitions(epoch, key);
  logger.info("Joiner got epoch = " + epoch + ", partition = " + partition + ", parts = " + partitions);
  if (partitions.epoch < epoch) {
    // we are in a new era
    if (partitions.partitions.size() != expected)
      throw new IllegalArgumentException("Should have " + expected + " partitions when new epoch starts.");
    logger.info("Reseting epoch to " + epoch);
    this.store.delete(key);
    partitions.epoch = epoch;
    partitions.partitions.clear();
    partitions.partitions.add(partition);
  } else if (partitions.epoch > epoch) {
    logger.info("Ignoring message for epoch " + epoch);
  } else {
    partitions.partitions.add(partition);
    if (partitions.partitions.size() == expected) {
      logger.info("Completed: " + key + " -> " + Integer.toString(epoch));
      collector.send(new OutgoingMessageEnvelope(new SystemStream("kafka", "completed-keys"), key, Integer.toString(epoch)));
    }
  }
  this.store.put(key, partitions.toString());
  logger.info("Join store in Task " + this.taskName + " " + key + " -> " + partitions.toString());
}
 
开发者ID:apache,项目名称:samza,代码行数:32,代码来源:Joiner.java

示例9: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
  String key = (String) envelope.getKey();
  String epoch = (String) envelope.getMessage();
  logger.info("Got key=" + key + ", epoch = " + epoch + " in checker...");
  checkEpoch(epoch);
  this.store.put(key, epoch);
}
 
开发者ID:apache,项目名称:samza,代码行数:9,代码来源:Checker.java

示例10: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
  messagesProcessed += 1;
  String input = (String) envelope.getMessage();
  Integer number = Integer.valueOf(input);
  Integer output = number.intValue() * -1;
  collector.send(new OutgoingMessageEnvelope(outputSystemStream, output.toString()));
  if (messagesProcessed >= maxMessages) {
    coordinator.shutdown(RequestScope.ALL_TASKS_IN_CONTAINER);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:12,代码来源:NegateNumberTask.java

示例11: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope incomingMessageEnvelope, MessageCollector messageCollector,
    TaskCoordinator taskCoordinator)
    throws Exception {

  Object message = incomingMessageEnvelope.getMessage();

  String key = new String((byte[]) incomingMessageEnvelope.getKey());
  Integer val = Integer.valueOf((String) message);

  LOG.info("Stream processor " + processorId + ";key=" + key + ";offset=" + incomingMessageEnvelope.getOffset()
      + "; totalRcvd=" + processedMessageCount + ";val=" + val + "; ssp=" + incomingMessageEnvelope
      .getSystemStreamPartition());

  // inject a failure
  if (val >= BAD_MESSAGE_KEY && processorId.equals(processorIdToFail)) {
    LOG.info("process method failing for msg=" + message);
    throw new Exception("Processing in the processor " + processorId + " failed ");
  }

  messageCollector.send(new OutgoingMessageEnvelope(new SystemStream(outputSystem, outputTopic), message));
  processedMessageCount++;

  synchronized (endLatch) {
    if (Integer.valueOf(key) < BAD_MESSAGE_KEY) {
      endLatch.countDown();
    }
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:30,代码来源:TestZkStreamProcessorBase.java

示例12: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator)
    throws Exception {
  SamzaStream output = (SamzaStream) this.getOutputStream();
  if (output == null)
    return; // if there is no output stream, do nothing
  output.setCollector(collector);
  ContentEvent event = (ContentEvent) envelope.getMessage();
  output.put(event);
}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:11,代码来源:SamzaEntranceProcessingItem.java

示例13: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector,
                    TaskCoordinator coordinator) throws Exception {

    GenericRecord genericRecord = (GenericRecord) envelope.getMessage();

    FortuneRequest request = (FortuneRequest) SpecificData.get().deepCopy(FortuneRequest.SCHEMA$, genericRecord);

    String fortune = "Unknown";
    double certainty = 0.0;
    if (request.getFirstName().equals("Ragnar")) {
        fortune = "The sons of Ragnar Lothbrok will be spoken of as long as men have tongues to speak.";
        certainty = 1.0;
    }
    else if (request.getFirstName().toString().equals("Lagartha")) {
        if (request.getQuestion().toString().startsWith("Will")) {
            fortune = "I cannot see another child no matter how far i look";
            certainty = 0.5;
        }
        else {
            fortune = "I see a harvest celebrated in blood. I see a trickster whose weapon cleaves you. I see a city made of marble and a burning, broiling ocean.";
            certainty = 0.9;
        }
    }

    Headers header = Headers.newBuilder()
            .setTimestamp(request.header.getTimestamp())
            .build();
    Fortune fortuneRec = Fortune.newBuilder()
            .setHeader(header)
            .setAnswer(fortune)
            .setFirstName(request.getFirstName())
            .setLastName(request.getLastName())
            .setQuestion(request.getQuestion())
            .setDegreeOfCertainty(certainty)
            .build();
    collector.send(new OutgoingMessageEnvelope(outStream, fortuneRec));
}
 
开发者ID:theduderog,项目名称:hello-samza-confluent,代码行数:39,代码来源:SeerTask.java

示例14: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator taskCoordinator) throws Exception {
    String key = (String) envelope.getKey();
    Integer value = (Integer) envelope.getMessage();
    Integer newValue = value * 10;
    collector.send(new OutgoingMessageEnvelope(outputStream, key, newValue));
}
 
开发者ID:theduderog,项目名称:hello-samza-confluent,代码行数:9,代码来源:TestProcessTask.java

示例15: process

import org.apache.samza.system.IncomingMessageEnvelope; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator taskCoordinator) throws Exception {
    String key = (String) envelope.getKey();
    Integer value = (Integer) envelope.getMessage();
    counterList.add(new AbstractMap.SimpleEntry<String, Integer>(key, value));
}
 
开发者ID:theduderog,项目名称:hello-samza-confluent,代码行数:8,代码来源:TestWindowTask.java


注:本文中的org.apache.samza.system.IncomingMessageEnvelope.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。