0
votes

I'm just trying to make a simple test for RabbitMQ, and I have Erlang installed as well as RabbitMQ running. My receiver:

private final static String QUEUE_NAME = "hello";

public static void main(String[] argv) throws Exception {
   ConnectionFactory factory = new ConnectionFactory();
   factory.setHost("localhost");
   Connection connection = factory.newConnection();
   Channel channel = connection.createChannel();

   channel.queueDeclare(QUEUE_NAME, false, false, false, null);
   System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    Consumer consumer = new DefaultConsumer(channel) {
    @Override
        public void handleDelivery(String consumerTag, Envelope envelope,
                BasicProperties properties, byte[] body) throws IOException 
        {
            // TODO Auto-generated method stub
            String message = new String(body, "UTF-8");
            System.out.println(" [x] Received '" + message + "'");
        }
     };
     channel.basicConsume(QUEUE_NAME, true, consumer);
}

It never prints out the first sysout, because it gets stuck declaring the queue on "channel.queueDeclare" line. Rabbit log says it is accepting AMQP connection and user guest gets authenticated and granted access to vhost.

Any help would be appreciated.

1

1 Answers

0
votes

I just copied/pasted your code with no problems...

 [*] Waiting for messages. To exit press CTRL+C
 [x] Received 'foo'

I suggest you enable the management plugin and explore the admin UI.

Why did you add the tags since this question has nothing to do with Spring and you are using the native client directly?