我已經運行與下面的代碼的Hello World RabbitMQ的例子:RabbitMQ HelloWorld消息在本地主機上被阻止?
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Send {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws java.io.IOException {
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!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}
和:
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
public class Recv {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv)
throws java.io.IOException,
java.lang.InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
}
}
當我運行它監聽的隊列接收器和發送者表示,其發送消息,但似乎並沒有結束。然後我運行:
rabbitmqctl list_queues
隊列肯定是在創建。
然而,當我運行:
rabbitmqctl list_connections
我得到以下輸出
[email protected]:~$ sudo rabbitmqctl list_connections
ls: cannot access /etc/rabbitmq/rabbitmq.conf.d: No such file or directory
Listing connections ...
guest 127.0.0.1 64700 blocked
guest 127.0.0.1 64709 blocked
guest 127.0.0.1 64614 blocked
guest 127.0.0.1 64716 blocked
guest 127.0.0.1 64717 blocked
guest 127.0.0.1 64701 blocked
guest 127.0.0.1 64699 blocking
guest 127.0.0.1 64613 blocking
guest 127.0.0.1 64708 blocking
guest 127.0.0.1 64718 blocked
guest 127.0.0.1 64706 blocked
...done.
SO由於某些原因的RabbitMQ服務器阻止我的連接? 有誰知道我需要做什麼? 謝謝, 本
謝謝,我忘了這篇文章。這是最終的問題。應該自己更新它 –