Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Message Key as Channel ID for Inbound Transport #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import kafka.consumer.ConsumerIterator;
import kafka.consumer.KafkaStream;
import kafka.javaapi.consumer.ConsumerConnector;
import kafka.message.MessageAndMetadata;
import kafka.utils.ZKStringSerializer$;
import kafka.utils.ZkUtils;
import org.I0Itec.zkclient.ZkClient;
Expand Down Expand Up @@ -79,12 +80,14 @@ public void run()
{
try
{
byte[] bytes = consumer.receive();
if (bytes != null && bytes.length > 0) {
MessageAndMetadata<byte[], byte[]> mm = consumer.receive();
if (mm != null && mm.message().length > 0) {
byte[] bytes = mm.message();
String channelId = new String(mm.key());
ByteBuffer bb = ByteBuffer.allocate(bytes.length);
bb.put(bytes);
bb.flip();
byteListener.receive(bb, "");
byteListener.receive(bb, channelId);
bb.clear();
}
}
Expand Down Expand Up @@ -195,7 +198,7 @@ public void shutdown() {

private class KafkaEventConsumer extends KafkaComponentBase {
private Semaphore connectionLock;
private final BlockingQueue<byte[]> queue = new LinkedBlockingQueue<byte[]>();
private final BlockingQueue<MessageAndMetadata<byte[], byte[]>> queue = new LinkedBlockingQueue<>();
private ConsumerConnector consumer;
private ExecutorService executor;

Expand All @@ -216,7 +219,7 @@ private class KafkaEventConsumer extends KafkaComponentBase {
List<KafkaStream<byte[], byte[]>> streams = consumerMap.get(topic);
executor = Executors.newFixedThreadPool(numThreads);
int threadNumber = 0;
for (final KafkaStream stream : streams)
for (final KafkaStream<byte[], byte[]> stream : streams)
{
try
{
Expand All @@ -241,7 +244,7 @@ public synchronized void init() throws MessagingException
;
}

byte[] receive() throws MessagingException {
MessageAndMetadata<byte[], byte[]> receive() throws MessagingException {
// wait to receive messages if we are not connected
if (!isConnected())
{
Expand All @@ -254,16 +257,16 @@ byte[] receive() throws MessagingException {
; // ignored
}
}
byte[] bytes = null;
MessageAndMetadata<byte[], byte[]> mm = null;
try
{
bytes = queue.poll(100, TimeUnit.MILLISECONDS);
mm = queue.poll(100, TimeUnit.MILLISECONDS);
}
catch (Exception e)
{
; // ignore
}
return bytes;
return mm;
}

@Override
Expand Down Expand Up @@ -339,7 +342,8 @@ public void run() {
{
try
{
queue.offer(it.next().message(), 100, TimeUnit.MILLISECONDS);
MessageAndMetadata<byte[], byte[]> mm = it.next();
queue.offer(mm, 100, TimeUnit.MILLISECONDS);
}
catch (InterruptedException ex)
{
Expand Down