7

我是 rabbitmq 的新手,但由于某些(未知)原因,“hello world”程序对我不起作用。send.py 和 receive.py 只是从教程页面复制和粘贴:

http://www.rabbitmq.com/tutorials/tutorial-one-python.html

rabbitmq 是在 RHEL 6 上使用“yum”安装的。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!”。

它出什么问题了?

4

2 回答 2

12

首先启用管理控制台

sudo rabbitmq-plugins enable rabbitmq_management

然后打开浏览器

http://localhost:55672

登录方式:访客/访客

在我的情况下,它是内存(低于 2 Giga)和消息“此节点的磁盘可用空间警报已响起。它将阻止传入的网络流量,直到可用空间量超过限制。”

编辑文件/etc/rabbitmq/rabbitmq.config如下:

 [
    {rabbit, [{disk_free_limit, {mem_relative, 0.1}}]}
 ]

现在重启rabbit服务:

service rabbitmq-server stop
service rabbitmq-server start
于 2012-05-25T18:41:53.580 回答
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
于 2017-07-20T15:10:01.477 回答