Search in sources :

Example 6 with Message

use of kafka.message.Message in project heron by twitter.

the class TestUtils method verifyMessage.

public static boolean verifyMessage(String key, String message, KafkaTestBroker broker, SimpleConsumer simpleConsumer) {
    long lastMessageOffset = KafkaUtils.getOffset(simpleConsumer, TestUtils.TOPIC, 0, OffsetRequest.LatestTime()) - 1;
    ByteBufferMessageSet messageAndOffsets = KafkaUtils.fetchMessages(TestUtils.getKafkaConfig(broker), simpleConsumer, new Partition(Broker.fromString(broker.getBrokerConnectionString()), TestUtils.TOPIC, 0), lastMessageOffset);
    MessageAndOffset messageAndOffset = messageAndOffsets.iterator().next();
    Message kafkaMessage = messageAndOffset.message();
    ByteBuffer messageKeyBuffer = kafkaMessage.key();
    String keyString = null;
    String messageString = new String(Utils.toByteArray(kafkaMessage.payload()));
    if (messageKeyBuffer != null) {
        keyString = new String(Utils.toByteArray(messageKeyBuffer));
    }
    assertEquals(key, keyString);
    assertEquals(message, messageString);
    return true;
}
Also used : Message(kafka.message.Message) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet) ByteBuffer(java.nio.ByteBuffer)

Example 7 with Message

use of kafka.message.Message in project storm by apache.

the class KafkaBoltTest method mockSingleMessage.

private static ByteBufferMessageSet mockSingleMessage(byte[] key, byte[] message) {
    ByteBufferMessageSet sets = mock(ByteBufferMessageSet.class);
    MessageAndOffset msg = mock(MessageAndOffset.class);
    final List<MessageAndOffset> msgs = ImmutableList.of(msg);
    doReturn(msgs.iterator()).when(sets).iterator();
    Message kafkaMessage = mock(Message.class);
    doReturn(ByteBuffer.wrap(key)).when(kafkaMessage).key();
    doReturn(ByteBuffer.wrap(message)).when(kafkaMessage).payload();
    doReturn(kafkaMessage).when(msg).message();
    return sets;
}
Also used : Message(kafka.message.Message) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet)

Example 8 with Message

use of kafka.message.Message in project storm by apache.

the class KafkaBoltTest method verifyMessage.

private boolean verifyMessage(String key, String message) {
    long lastMessageOffset = KafkaUtils.getOffset(simpleConsumer, kafkaConfig.topic, 0, OffsetRequest.LatestTime()) - 1;
    ByteBufferMessageSet messageAndOffsets = KafkaUtils.fetchMessages(kafkaConfig, simpleConsumer, new Partition(Broker.fromString(broker.getBrokerConnectionString()), kafkaConfig.topic, 0), lastMessageOffset);
    MessageAndOffset messageAndOffset = messageAndOffsets.iterator().next();
    Message kafkaMessage = messageAndOffset.message();
    ByteBuffer messageKeyBuffer = kafkaMessage.key();
    String keyString = null;
    String messageString = new String(Utils.toByteArray(kafkaMessage.payload()));
    if (messageKeyBuffer != null) {
        keyString = new String(Utils.toByteArray(messageKeyBuffer));
    }
    assertEquals(key, keyString);
    assertEquals(message, messageString);
    return true;
}
Also used : Message(kafka.message.Message) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet) ByteBuffer(java.nio.ByteBuffer)

Example 9 with Message

use of kafka.message.Message in project elasticsearch-river-kafka by endgameinc.

the class JsonMessageHandlerTest method testReadMessage.

public void testReadMessage() throws Exception {
    JsonMessageHandler h = new JsonMessageHandler(null);
    byte[] json = toJson(rec).getBytes();
    Message message = createMock(Message.class);
    expect(message.payload()).andReturn(ByteBuffer.wrap(json));
    replay(message);
    try {
        h.readMessage(message);
    } catch (Exception e) {
        fail("This should not fail");
    }
    verify(message);
}
Also used : Message(kafka.message.Message)

Example 10 with Message

use of kafka.message.Message in project elasticsearch-river-kafka by endgameinc.

the class RawMessageHandlerTest method testIt.

public void testIt() throws Exception {
    byte[] data = "somedata".getBytes();
    List<String> l = new ArrayList<>();
    MessageHandler m = new RawMessageHandler();
    Message message = createMock(Message.class);
    expect(message.payload()).andReturn(ByteBuffer.wrap(data));
    BulkRequestBuilder bulkRequestBuilder = createMock(BulkRequestBuilder.class);
    expect(bulkRequestBuilder.add(aryEq(data), eq(0), eq(data.length), eq(false))).andReturn(null);
    replay(message, bulkRequestBuilder);
    m.handle(bulkRequestBuilder, message);
    verify(bulkRequestBuilder, message);
}
Also used : Message(kafka.message.Message) ArrayList(java.util.ArrayList) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder)

Aggregations

Message (kafka.message.Message)13 ByteBufferMessageSet (kafka.javaapi.message.ByteBufferMessageSet)5 MessageAndOffset (kafka.message.MessageAndOffset)5 ByteBuffer (java.nio.ByteBuffer)3 BagheeraMessage (com.mozilla.bagheera.BagheeraProto.BagheeraMessage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 Producer (kafka.javaapi.producer.Producer)2 ProducerConfig (kafka.producer.ProducerConfig)2 Schema (org.apache.avro.Schema)2 Encoder (org.apache.avro.io.Encoder)2 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)2 Test (org.junit.Test)2 Timer (com.codahale.metrics.Timer)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 KeyValueSink (com.mozilla.bagheera.sink.KeyValueSink)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1