Search in sources :

Example 11 with KafkaStream

use of kafka.consumer.KafkaStream in project voltdb by VoltDB.

the class KafkaLoader method getConsumerExecutor.

private ExecutorService getConsumerExecutor(KafkaConsumerConnector consumer, CSVDataLoader loader) throws Exception {
    Map<String, Integer> topicCountMap = new HashMap<>();
    // generate as many threads as there are partitions defined in kafka config
    ExecutorService executor = Executors.newFixedThreadPool(m_config.kpartitions);
    topicCountMap.put(m_config.topic, m_config.kpartitions);
    Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.m_consumer.createMessageStreams(topicCountMap);
    List<KafkaStream<byte[], byte[]>> streams = consumerMap.get(m_config.topic);
    // now launch all the threads for partitions.
    for (final KafkaStream stream : streams) {
        KafkaConsumer bconsumer = new KafkaConsumer(stream, loader, m_config);
        executor.submit(bconsumer);
    }
    return executor;
}
Also used : HashMap(java.util.HashMap) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) KafkaStream(kafka.consumer.KafkaStream)

Example 12 with KafkaStream

use of kafka.consumer.KafkaStream in project incubator-gobblin by apache.

the class MockKafkaStream method createMockStream.

@SuppressWarnings("unchecked")
private static KafkaStream<byte[], byte[]> createMockStream(BlockingQueue<FetchedDataChunk> queue) {
    KafkaStream<byte[], byte[]> stream = (KafkaStream<byte[], byte[]>) Mockito.mock(KafkaStream.class);
    ConsumerIterator<byte[], byte[]> it = new ConsumerIterator<>(queue, -1, new DefaultDecoder(new VerifiableProperties()), new DefaultDecoder(new VerifiableProperties()), "clientId");
    Mockito.when(stream.iterator()).thenReturn(it);
    return stream;
}
Also used : VerifiableProperties(kafka.utils.VerifiableProperties) ConsumerIterator(kafka.consumer.ConsumerIterator) DefaultDecoder(kafka.serializer.DefaultDecoder) KafkaStream(kafka.consumer.KafkaStream)

Aggregations

KafkaStream (kafka.consumer.KafkaStream)12 List (java.util.List)9 HashMap (java.util.HashMap)6 Properties (java.util.Properties)5 ConsumerConfig (kafka.consumer.ConsumerConfig)5 ConsumerConnector (kafka.javaapi.consumer.ConsumerConnector)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutorService (java.util.concurrent.ExecutorService)3 MessageAndMetadata (kafka.message.MessageAndMetadata)3 ConsumerIterator (kafka.consumer.ConsumerIterator)2 Whitelist (kafka.consumer.Whitelist)2 VerifiableProperties (kafka.utils.VerifiableProperties)2 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)1 Stopwatch (com.google.common.base.Stopwatch)1 MessageDecoder (com.jeesuite.kafka.serializer.MessageDecoder)1 ByteBufferInputRowParser (io.druid.data.input.ByteBufferInputRowParser)1 Firehose (io.druid.data.input.Firehose)1 IAE (io.druid.java.util.common.IAE)1 ISE (io.druid.java.util.common.ISE)1