简体   繁体   English

Rabbitmq,连接到远程主机

[英]Rabbitmq , connect to remote host

I want to connect to rabbitmq remotely, my code is 我想远程连接到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 its the local ipv4 address of PC with rabbitmq, but i have the following error 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)

My rabbitmq.config contein one line: [{loopback_users, []}]. 我的rabbitmq.config包含一行: [{loopback_users, []}]. Any suggestions? 有什么建议么?

最后,我将配置更改为[{rabbit, [{loopback_users, []}]}].

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM