簡體   English   中英

Rabbitmq,連接到遠程主機

[英]Rabbitmq , connect to remote host

我想遠程連接到rabbitmq,我的代碼是

 public class ReceiveLogsDirect {

      private static final String EXCHANGE_NAME = "direct_logs";

      public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
          factory.setUsername("guest");
          factory.setPassword("guest");
          factory.setVirtualHost("/");
          factory.setHost("192.168.23.214");
          factory.setPort(5672);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        String queueName = channel.queueDeclare().getQueue();


          channel.queueBind(queueName, EXCHANGE_NAME, "user_one");

        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

        Consumer consumer = new DefaultConsumer(channel) {
          @Override
          public void handleDelivery(String consumerTag, Envelope envelope,
                                     AMQP.BasicProperties properties, byte[] body) throws IOException {
            String message = new String(body, "UTF-8");
            System.out.println(" [x] Received '" + envelope.getRoutingKey() + "':'" + message + "'");
          }
        };
        channel.basicConsume(queueName, true, consumer);
      }
    }

192.168.23.214它與Rabbitmq的PC的本地ipv4地址,但我有以下錯誤

Exception in thread "main" com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:349)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:63)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:911)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:870)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:828)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:979)
at tutorial5.ReceiveLogsDirect.main(ReceiveLogsDirect.java:21)

我的rabbitmq.config包含一行: [{loopback_users, []}]. 有什么建議么?

最后,我將配置更改為[{rabbit, [{loopback_users, []}]}].

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM