Skip to content

Instantly share code, notes, and snippets.

@honnix
Created November 25, 2013 14:51
Show Gist options
  • Save honnix/7642359 to your computer and use it in GitHub Desktop.
Save honnix/7642359 to your computer and use it in GitHub Desktop.
rabbitmq receiver
package com.ericsson.research.axon.messenger;
import java.io.IOException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
/**
*
*
* @author honnix
*/
public class Recv {
// _9e-AzbuRPy_8eRD17IQPg
private final static String EXCHANGE_NAME = "streams.KzPCQUGzTtSrBCsxghIbTw";
public static void main(String[] argv)
throws java.io.IOException,
java.lang.InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("axondev.cf.ericsson.net");
Connection connection = factory.newConnection();
final Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); // FIXME
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
boolean autoAck = true;
channel.basicConsume(queueName, autoAck, "myConsumerTag",
new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body)
throws IOException {
//long deliveryTag = envelope.getDeliveryTag();
// (process the message components here ...)
//channel.basicAck(deliveryTag, false);
// {"value":"10.9","timestamp":"2013-11-25T15:29:34.000","stream_id":"_9e-AzbuRPy_8eRD17IQPg"}
String json = new String(body);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment