解决java RabbitMQ初次启动发送端basicPublish阻塞问题

发送端代码如下

public class SendClient {
    private final static String QUEUE_NAME = "hello";
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        String message = "Hello World";
        System.out.println("发送前");
        channel.basicPublish("",QUEUE_NAME,null,message.getBytes());

        System.out.println("send Message: "+message);
        channel.close();
        connection.close();
    }
}

最开始的时候一直会在channel.queueDeclare 这地方阻塞,官网上给了个解决办法:http://www.rabbitmq.com/tutorials/tutorial-one-java.html

Sending doesn't work!

If this is your first time using RabbitMQ and you don't see the "Sent" message then you may be left scratching your head wondering what could be wrong. Maybe the broker was started without enough free disk space (by default it needs at least 200 MB free) and is therefore refusing to accept messages. Check the broker logfile to confirm and reduce the limit if necessary. The configuration file documentation will show you how to set disk_free_limit.


只需要修改下RabbitMQ的配置文件即可,默认位置在AppDate%\RabbitMQ 下的rabbitmq.config。


[{rabbit, [{disk_free_limit, "500MB"}]}].


disk_free_limit增加到500M即可,然后重启服务即可。

你可能感兴趣的:(项目经验)