我只是想为RabbitMQ做一个简单的测试,我安装了Erlang以及RabbitMQ运行。 我的接收者:
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);
}
它永远不会打印出第一个sysout,因为它被卡住了声明队列在" channel.queueDeclare"线。 Rabbit日志表示它正在接受AMQP连接,并且用户guest被验证并被授予对vhost的访问权。
任何帮助都将不胜感激。
答案 0 :(得分:0)
我只是复制/粘贴你的代码没有问题......
[*] Waiting for messages. To exit press CTRL+C
[x] Received 'foo'
我建议你启用管理插件并浏览管理界面。
为什么添加spring-amqp spring-rabbitmq标记,因为这个问题与Spring无关,而您直接使用本机客户端?