阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

RabbitMQ远程调用测试用例

211次阅读
没有评论

共计 3634 个字符,预计需要花费 10 分钟才能阅读完成。

RabbitMQ 远程调用测试,使用外部机器 192.168.174.132 上的 RabbitMQ,使用之前需要对远程调用进行配置,操作过程见另一篇“解决 RabbitMQ 远程不能访问的问题”http://www.linuxidc.com/Linux/2014-10/107917.htm。

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:

RabbitMQ 远程调用测试用例RabbitMQ 远程调用测试用例

CentOS 5.6 安装 RabbitMQ http://www.linuxidc.com/Linux/2013-02/79508.htm

RabbitMQ 客户端 C ++ 安装详细记录 http://www.linuxidc.com/Linux/2012-02/53521.htm

用 Python 尝试 RabbitMQ http://www.linuxidc.com/Linux/2011-12/50653.htm

RabbitMQ 集群环境生产实例部署 http://www.linuxidc.com/Linux/2012-10/72720.htm

Ubuntu 下 PHP + RabbitMQ 使用 http://www.linuxidc.com/Linux/2010-07/27309.htm

在 CentOS 上安装 RabbitMQ 流程 http://www.linuxidc.com/Linux/2011-12/49610.htm

RabbitMQ 的详细介绍 :请点这里
RabbitMQ 的下载地址 :请点这里

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计3634字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中