我是rabbitmq的新手,但由于某些(未知)原因,“hello world”程序对我不起作用。 send.py和receive.py只是从教程页面复制并粘贴:
http://www.rabbitmq.com/tutorials/tutorial-one-python.html
在RHEL 6上使用“yum”安装rabbitmq.Python版本为2.6。 我使用了启动服务器
$ service rabbitmq-server start
并打印出“成功”。
运行send.py和receive.py时没有错误或警告消息:
$ python send.py
[x] Sent 'Hello World!'
$ python receive.py
[*] Waiting for messages. To exit press CTRL+C
然后它永远不会打印“Hello World!”。
它出什么问题了?
首先启用管理控制台
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
你必须启动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