【发布时间】:2014-12-12 20:16:34
【问题描述】:
我正在尝试使用默认设置从 amqp 客户端连接到 aqtivemq 服务器。它总是给出错误消息说连接被拒绝。然后我用rabbitmq服务器而不是activemq服务器尝试了它,它工作正常。我想知道activemq是否需要一个linux库来通信。
使用的未连接的 Activemq 服务器版本:5.4.2 / 5.10.0 使用的 Rabitmq 版本:3.3.5
rabitmq 示例客户端代码
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Cache {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv)
throws java.io.IOException {
//creating the connection factory
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
//Creating a connection to the server
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
//declaring a queuw
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
//publishing the queue the queue
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
//closing the connection
channel.close();
connection.close();
}
}
以下代码行失败
//Creating a connection to the server
Connection connection = factory.newConnection();
我该如何解决这个问题?
【问题讨论】:
-
日志有错误吗?