2014-10-17 36 views
0

我試圖用默認設置從amqp客戶端連接到aqtivemq服務器。它總是給出錯誤消息,說連接被拒絕。然後,我用rabbitmq服務器而不是activemq服務器嘗試了它,它工作正常。我想知道activemq是否需要一個linux庫來進行通信。使用Amqp客戶端未連接到activemq服務器。

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(); 

我該如何解決這個問題?駱駝春天的URI(從和):

+0

任何錯誤的日誌? – 2014-10-17 09:20:20

回答

1

我發現了一個類似的問題,我固定檢查交流宣佈爲等於用來發布渠道,以這樣的方式

@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(); 
} 

請carefoul DSL上下文和JUnit類必須引用相同的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/