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

本文介绍了一个RabbitMQ消息发送端程序,在尝试发送消息时遇到的阻塞问题及其解决方案。通过调整RabbitMQ的disk_free_limit配置项,并将其从默认的200MB增加到500MB,解决了消息发送失败的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

发送端代码如下
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即可,然后重启服务即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值