node.js subscriber client for rabbitmq (implements topics (ExcahangeName))

I am trying to write a node.js client(subscriber module) to consume messages from rabbitmq(AMQP). I am trying to implement topics (exchangeName) in rabbitmq.

I am trying to use either (easy-amqp) or postwait for this task.

I have written a publisher method in java and want to write a subscriber method in the javascript( node.js).

My java program works fine I am able to send out messages to rabbitmq.

I think I have messed up subscriber method. when I run the subscriber method it doesn't give me any error and also doesn't print any messages to the console.

My java method is somewhat like

//Publisher (written in java)

Connection connection = null;
Channel channel = null;
String routingKey =null;

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");

connection = factory.newConnection();
channel = connection.createChannel();

//publishing to a exchange_name topic

channel.exchangeDeclare(EXCHANGE_NAME, "topic");

//set the routing key

routingKey = "anonymous.info" ;

channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
System.out.println("Sent '" + routingKey + "':'" + message + "'");

//Subscriber method in js (node.js) //using (postwait- node-amqp )

var amqp = require('amqp');

var connection = amqp.createConnection({defaultExchangeName: "topic"});

// Wait for connection to become established.
   connection.on('ready', function () {

  connection.queue('anonymous.info', function(q){
      // Catch all messages
      q.bind('#');

      // Receive messages
      q.subscribe(function (message) {
        // Print messages to stdout
        console.log(message);
      });
  });
});

This doesn't give me any error but it even doesn't print any messages to the console.


So then I came across another library called easy-amqp. I gave it a try

// subscriber using easy-amqp.

var easyamqp = require('easy-amqp');

var connection = easyamqp.createConnection("amqp://localhost:5672");



// setting the exchange
connection.exchange('topic')

connection.on('ready', function () {

  connection.queue('anonymous.info', function(q){

      q.bind('#');

      // Receive messages
      q.subscribe(function (message) {
        // Print messages to stdout
        console.log(message);
      });
  });
});

This also doesn't give me desired result.

Did you check the console log? check it first.

connection.on('ready', function () {
  **console.log('ready function called!');**

  connection.queue('anonymous.info', function(q){
      // Catch all messages
      q.bind('#');

      // Receive messages
      q.subscribe(function (message) {
        // Print messages to stdout
        console.log(message);
      });
  });
});