欢迎点击「算法与编程之美」↑关注我们!
本文首发于微信公众号:"算法与编程之美",欢迎关注,及时了解更多此系列文章
作者|olive
来源|
https://blog.csdn.net/asd1098626303/article/details/77849562
发送端代码如下
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即可,然后重启服务即可。
拓展阅读:
where2go 团队
微信号:算法与编程之美
温馨提示:点击页面右下角“写留言”发表评论,期待您的参与!期待您的转发!