• RabbitMQ远程调用测试用例


    RabbitMQ远程调用测试,使用外部机器192.168.174.132上的RabbitMQ,使用之前需要对远程调用进行配置,操作过程见博文“解决RabbitMQ远程不能访问的问题”。

    SendTest:

    package com.mq.rabbitmq.rabbitmqtest;
     
    import java.util.Date;
     
    import com.rabbitmq.client.ConnectionFactory;
    import com.rabbitmq.client.Connection;
    import com.rabbitmq.client.Channel;
    import com.rabbitmq.client.QueueingConsumer;
     
    public class ReceiveTest {
        private final static String QUEUE_NAME = "ftpAgent";
        private final static String userName = "admin";
        private final static String password = "admin";
        private final static String virtualHost = "/";
        private final static int portNumber = 5672;
        private final static String hostName = "master";
        private final static String host = "192.168.174.132";
     
        public static void main(String[] argv) throws java.io.IOException,
                java.lang.InterruptedException {
     
            ConnectionFactory factory = new ConnectionFactory();
    //      factory.setHost("192.168.174.160");
            factory.setUsername(userName);
            factory.setPassword(password);
    //      factory.setVirtualHost(virtualHost);
            factory.setHost(host);
            factory.setPort(portNumber);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
    //      channel.queueDeclare(QUEUE_NAME, false, false, false, null);
     
            System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
             
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(QUEUE_NAME, true, consumer);
     
            Date nowTime = new Date();
             
            while (true) {
              QueueingConsumer.Delivery delivery = consumer.nextDelivery();
              String message = new String(delivery.getBody());
              System.out.println("RecieveTime: " + nowTime);
              System.out.println(" [x] Received '" + message + "'");
            }
     
        }
    }
    

      

    ReceiveTest:

    package com.mq.rabbitmq.rabbitmqtest;
     
    import java.util.Date;
     
    import com.rabbitmq.client.ConnectionFactory;
    import com.rabbitmq.client.Connection;
    import com.rabbitmq.client.Channel;
    import com.rabbitmq.client.QueueingConsumer;
     
    public class ReceiveTest {
        private final static String QUEUE_NAME = "ftpAgent";
        private final static String userName = "admin";
        private final static String password = "admin";
        private final static String virtualHost = "/";
        private final static int portNumber = 5672;
        private final static String hostName = "master";
        private final static String host = "192.168.174.132";
     
        public static void main(String[] argv) throws java.io.IOException,
                java.lang.InterruptedException {
     
            ConnectionFactory factory = new ConnectionFactory();
    //      factory.setHost("192.168.174.160");
            factory.setUsername(userName);
            factory.setPassword(password);
    //      factory.setVirtualHost(virtualHost);
            factory.setHost(host);
            factory.setPort(portNumber);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
    //      channel.queueDeclare(QUEUE_NAME, false, false, false, null);
     
            System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
             
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(QUEUE_NAME, true, consumer);
     
            Date nowTime = new Date();
             
            while (true) {
              QueueingConsumer.Delivery delivery = consumer.nextDelivery();
              String message = new String(delivery.getBody());
              System.out.println("RecieveTime: " + nowTime);
              System.out.println(" [x] Received '" + message + "'");
            }
     
        }
    }
    

      

    运行结果:

    SendTest:

    wKioL1QFJQuThFCJAADsngw7JYs780.jpg

    ReceiveTest:

    wKioL1QFJVWBPv7YAAD_Zh5tZzU367.jpg

    博客地址: http://www.cnblogs.com/dwf07223,本文以学习、研究和分享为主,欢迎转载,转载请务必保留此出处。若本博文中有不妥或者错误处请不吝赐教。

  • 相关阅读:
    2018年度总结
    SQL特殊comment语法
    mysql 主从复制change master to
    mysql 主从复制参数slave_net_timeout
    show master status, show slave status中的Executed_Gtid_Set
    mysql重复start slave、stop slave测试
    golang database sql DSN (Data Source Name)中的timeout, readTimeout
    mysql show master status为空值
    Linux 建立 TCP 连接的超时时间分析(解惑)
    golang 原子操作函数
  • 原文地址:https://www.cnblogs.com/dwf07223/p/3991598.html
Copyright © 2020-2023  润新知