我是rabbitmq的新手,但由于某些(未知)原因,“你好 世界“计划对我不起作用。 send.py和receive.py只是从中复制并粘贴 教程页面:
http://www.rabbitmq.com/tutorials/tutorial-one-python.html
使用RHEL 6上的“yum”安装rabbitmq.Python版本为2.6。 我使用
启动了服务器$ service rabbitmq-server start
并打印出“SUCCESS”。
运行send.py和没有错误或警告消息 receive.py:
$ python send.py
[x] Sent 'Hello World!'
$ python receive.py
[*] Waiting for messages. To exit press CTRL+C
然后它永远不会打印“Hello World!”。
它出了什么问题?
答案 0 :(得分:12)
首先启用管理控制台
sudo rabbitmq-plugins enable rabbitmq_management
然后打开浏览器
http://localhost:55672
登录:来宾/来宾
在我的情况下,它是内存(2千兆以下)和消息“此节点的磁盘可用空间警报已关闭。它将阻止传入的网络流量,直到可用空间量超过限制。”
按如下方式编辑文件/etc/rabbitmq/rabbitmq.config
:
[
{rabbit, [{disk_free_limit, {mem_relative, 0.1}}]}
]
现在重启兔子服务:
service rabbitmq-server stop
service rabbitmq-server start
答案 1 :(得分:0)
你必须开始Rabbit MQ Serever
。在Windows文件名中:RabbitMQ Service - start
。您可以使用以下代码:
import java.io.IOException;
import java.util.ResourceBundle;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class NewTaskController implements Runnable {
private final String message;
private static final String EXCHANGE_NAME = "test";
private static final String ROUTING_KEY = "test";
public NewTaskController(final String message) {
this.message = message;
}
@Override
public void run() {
//getting data from application.properties
//for the rabbit_mq configuration
ResourceBundle mRB = ResourceBundle.getBundle("application");
System.out.println("*****NewTaskController************"+mRB.getString("rabbitmq.port"));
String rabbitmq_username = mRB.getString("rabbitmq.username");
String rabbitmq_password = mRB.getString("rabbitmq.password");
String rabbitmq_hostname = mRB.getString("rabbitmq.hostname");
int rabbitmq_port = Integer.parseInt(mRB.getString("rabbitmq.port"));
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(rabbitmq_username);
factory.setPassword(rabbitmq_password);
factory.setHost(rabbitmq_hostname);
factory.setPort(rabbitmq_port);
Connection conn;
try {
conn = factory.newConnection();
Channel channel = conn.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);
String queueName = channel.queueDeclare().getQueue();
System.out.println(queueName);
channel.queueBind(queueName, EXCHANGE_NAME, ROUTING_KEY);
System.out.println("Producing message: " + message + " in thread: " + Thread.currentThread().getName());
channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, message.getBytes());
try {
channel.close();
} catch (TimeoutException e) {
e.printStackTrace();
}
conn.close();
} catch (IOException | TimeoutException e) {
e.printStackTrace();
}
}
}
application.properties file
rabbitmq.username=guest
rabbitmq.password=guest
rabbitmq.hostname=localhost
rabbitmq.port=5672