[英]Amqp client not connecting to activemq server.
我正在嘗試使用默認設置從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();
我該如何解決這個問題?
我發現了一個類似的問題,並通過以下方式固定檢查了聲明的交換是否等於用於發布的通道:
@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上下文中的URI(從和到)和JUnit類必須引用相同的Exchange和隊列,以防止reply-text = PRECONDITION_FAILED –虛擬主機'/'中隊列'QUEUE'的參數不等效錯誤或類似。 要檢查隊列/交換配置參數,請使用:
rabbitmqadmin -V / list queue
rabbitmqadmin -V test list exchanges
看看這個: http : //www.andreagirardi.it/blog/camel-and-rabbitmq-finally-how-to/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.