Source:
private void createKafkaConsumer(String name, final MessageChannel moduleInputChannel, Properties properties, ConsumerConnector connector) { if (name.startsWith(P2P_NAMED_CHANNEL_TYPE_PREFIX)) { validateConsumerProperties(name, properties, SUPPORTED_NAMED_CONSUMER_PROPERTIES); } else { validateConsumerProperties(name, properties, SUPPORTED_CONSUMER_PROPERTIES); } KafkaPropertiesAccessor accessor = new KafkaPropertiesAccessor(properties); Map<String, Integer> topicCountMap = new HashMap<String, Integer>(); int numThreads = 1; String topic = escapeTopicName(name); topicCountMap.put(topic, numThreads); Decoder<byte[]> valueDecoder = new DefaultDecoder(null); Decoder<Integer> keyDecoder = new IntegerEncoderDecoder(); Map<String, List<KafkaStream<Integer, byte[]>>> consumerMap = connector.createMessageStreams( topicCountMap, keyDecoder, valueDecoder); final KafkaStream<Integer, byte[]> stream = consumerMap.get(topic).iterator().next(); final DirectChannel bridge = new DirectChannel(); ReceivingHandler rh = new ReceivingHandler(connector); rh.setOutputChannel(moduleInputChannel); EventDrivenConsumer edc = new EventDrivenConsumer(bridge, rh); edc.setBeanName("inbound." + name); Binding consumerBinding = Binding.forConsumer(name, edc, moduleInputChannel, accessor); addBinding(consumerBinding); consumerBinding.start(); executor.submit(new Runnable() { @Override public void run() { System.out.println(Thread.currentThread()); ConsumerIterator<Integer, byte[]> it = stream.iterator(); while (it.hasNext()) { byte[] msg = it.next().message(); bridge.send(MessageBuilder.withPayload(msg).build()); } } }); }

Target:
private void createKafkaConsumer(String name, final MessageChannel moduleInputChannel, Properties properties, ConsumerConnector connector) { if (name.startsWith(P2P_NAMED_CHANNEL_TYPE_PREFIX)) { validateConsumerProperties(name, properties, SUPPORTED_NAMED_CONSUMER_PROPERTIES); } else { validateConsumerProperties(name, properties, SUPPORTED_CONSUMER_PROPERTIES); } KafkaPropertiesAccessor accessor = new KafkaPropertiesAccessor(properties); Map<String, Integer> topicCountMap = new HashMap<String, Integer>(); int numThreads = 1; String topic = escapeTopicName(name); topicCountMap.put(topic, numThreads); Decoder<byte[]> valueDecoder = new DefaultDecoder(null); Decoder<Integer> keyDecoder = new IntegerEncoderDecoder(); Map<String, List<KafkaStream<Integer, byte[]>>> consumerMap = connector.createMessageStreams( topicCountMap, keyDecoder, valueDecoder); final KafkaStream<Integer, byte[]> stream = consumerMap.get(topic).iterator().next(); final DirectChannel bridge = new DirectChannel(); ReceivingHandler rh = new ReceivingHandler(connector); rh.setOutputChannel(moduleInputChannel); EventDrivenConsumer edc = new EventDrivenConsumer(bridge, rh); edc.setBeanName("inbound." + name); Binding consumerBinding = Binding.forConsumer(name, edc, moduleInputChannel, accessor); addBinding(consumerBinding); consumerBinding.start(); executor.submit(new Runnable() { @Override public void run() { ConsumerIterator<Integer, byte[]> it = stream.iterator(); while (it.hasNext()) { byte[] msg = it.next().message(); bridge.send(MessageBuilder.withPayload(msg).build()); } } }); }