作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用默认设置从 amqp 客户端连接到 aqtivemq 服务器。它总是给出错误消息说连接被拒绝。然后我用rabbitmq服务器而不是activemq服务器尝试了它,它工作得很好。我想知道activemq是否需要linux库来通信。
使用的无法连接的 Activemq 服务器版本:5.4.2/5.10.0使用的Rabitmq版本:3.3.5
rabbitmq 示例客户端代码
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();
如何解决这个问题?
最佳答案
我发现了类似的问题,并修复了检查声明的交换是否等于用于发布的 channel ,如下所示:
@Test
public void test() throws KeyManagementException, NoSuchAlgorithmException, URISyntaxException, IOException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("10.211.55.20");
factory.setPort(5672);
factory.setVirtualHost("/");
factory.setUsername("guest");
factory.setPassword("guest");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare("KipcastDirect", "direct",
true, /* durable */
true, /* autodelete */
null); /* */
byte[] messageBodyBytes = "Hello, world!".getBytes();
AMQP.BasicProperties.Builder basic = new AMQP.BasicProperties.Builder();
AMQP.BasicProperties minBasic = basic.build();
minBasic = basic.priority(0).deliveryMode(1).build();
channel.basicPublish("KipcastDirect", "KipcastRouting", minBasic, messageBodyBytes);
System.out.println(" [x] Sent ");
channel.close();
}
请小心:Camel Spring DSL 上下文和 JUnit 类上的 URI(从和到)必须引用相同的 Exchange 和队列,以防止回复文本=PRECONDITION_FAILED – vhost '/' 中的队列 'QUEUE' 参数不存在等效误差或类似误差。要检查队列/交换配置参数,请使用:
rabbitmqadmin -V / list queue
rabbitmqadmin -V test list exchanges
看看这个:http://www.andreagirardi.it/blog/camel-and-rabbitmq-finally-how-to/
关于java - Amqp 客户端未连接到 activemq 服务器。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26421762/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!