qileilove

          blog已經(jīng)轉移至github,大家請訪問 http://qaseven.github.io/

          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:

          posted on 2014-09-04 09:40 順其自然EVO 閱讀(659) 評論(0)  編輯  收藏 所屬分類: 測試學習專欄

          <2014年9月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 玛沁县| 金乡县| 柘荣县| 兰溪市| 玛曲县| 炎陵县| 徐州市| 襄城县| 惠州市| 搜索| 瑞安市| 长垣县| 新竹县| 新河县| 公主岭市| 余江县| 满城县| 武定县| 巩义市| 肃宁县| 武安市| 疏勒县| 芦山县| 阿拉善右旗| 天门市| 怀远县| 延安市| 潮州市| 肥乡县| 德州市| 定襄县| 通许县| 方山县| 永顺县| 恭城| 安阳县| 涟源市| 黄梅县| 个旧市| 太白县| 呈贡县|