本例是一个简单的异步发送消息实例
1,发送端
@Test(groups = { "sunjun" })
public class RabbitmqTest {
private static Connection connection;
static {
ConnectionParameters params = new ConnectionParameters();
ConnectionFactory factory = new ConnectionFactory(params);
try {
connection = factory.newConnection("192.168.18.21",
AMQP.PROTOCOL.PORT);
} catch (IOException e) {
e.printStackTrace();
}
}
public void testSend() {
try {
Channel channel = connection.createChannel();
System.out.println(channel.toString());
Assert.assertNotNull(channel);
byte[] messageBodyBytes = "hello world".getBytes();
channel.basicPublish("exchangeName", "routingKey",
MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes);
} catch (Exception e) {
e.printStackTrace();
}
}
}
2,接收端
@Test(groups = { "sunjun" })
public class RabbitmqTestB {
private static Connection connection;
static {
ConnectionParameters params = new ConnectionParameters();
ConnectionFactory factory = new ConnectionFactory(params);
try {
connection = factory.newConnection("localhost", AMQP.PROTOCOL.PORT);
} catch (IOException e) {
e.printStackTrace();
}
}
public void testReceive() {
try {
Channel channel = connection.createChannel();
System.out.println(channel.toString());
Assert.assertNotNull(channel);
channel.exchangeDeclare("exchangeName", "direct");
channel.queueDeclare("queueName");
channel.queueBind("queueName", "exchangeName", "routingKey");
boolean noAck = false;
GetResponse response = channel.basicGet("queueName", true);
if (response == null) {
System.out.println("No message retrieved.");
} else {
AMQP.BasicProperties props = response.getProps();
byte[] body = response.getBody();
System.out.println(new String(body));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
先执行下发送端,再执行下接收端,输出:hello world
ok
分享到:
相关推荐
RabbitMQ rabbitmq-server-3.6.12-1.el6.noarch 及其安装所需要的软件打包都在这里面,主要报卡一下软件:socat-1.7.3.2.tar.gz、rabbitmq-server-3.6.12-1.el6.noarch.rpm、rabbitmq-release-signing-key.asc、otp_...
rabbitmq-server-3.10.5-1.el8.noarch.rpm
rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-3.11.13rabbitmq-server-...
1. **下载**:首先,你需要从官方网站下载适合你的Linux发行版的RabbitMQ版本,如"rabbitmq-server-generic-unix-3.5.4.tar.gz"。你可以使用wget命令或者直接在浏览器中下载。 2. **解压**:使用tar命令解压下载的...
rabbitmq-server-3.9.11.exe
标题中的“rabbitmq-server-3.6.5-1.noarch.rar”指的是RabbitMQ服务器的一个特定版本,即3.6.5版本。RabbitMQ是一个开源的消息队列系统,基于AMQP(Advanced Message Queuing Protocol)协议,用于在分布式系统中...
rabbitmq-server-3.8.8-1.el7.noarch
1. **下载与解压**:首先,从官方网站或者提供的链接下载`rabbitmq-server-mac-standalone-3.5.3.tar.gz`,然后使用`tar -zxvf rabbitmq-server-mac-standalone-3.5.3.tar.gz`命令将其解压缩。 2. **环境配置**:...
在您提供的资源中,“rabbitmq-server-generic-unix-3.5.7.tar.rar”是一个针对Linux平台的RabbitMQ服务器的离线安装包。这个版本为3.5.7,您需要在Windows环境下解压后再用于Linux系统。下面将详细介绍RabbitMQ的...
最新版linux rabbitmq-server-generic-unix-3.8.14.tar.xz最新版linux rabbitmq-server-generic-unix-3.8.14.tar.xz
rabbitmq-server-3.8.13-1.el7.noarch.rpm
rabbitmq-server-3.6.8-1.el7.noarch.rpm Linux安装rabbitmq,3.6.8版本
rabbitmq-server-3.9.7-1.el7.noarch.rpm
最新版linux rabbitmq-server-generic-unix-3.8.5.tar.xz
在本例中,我们关注的是`rabbitmq-server-3.6.15-1.el7.noarch.rpm`这个软件包,它是RabbitMQ服务器的3.6.15版本,针对的是Red Hat Enterprise Linux 7 (RHEL 7)或与其兼容的系统,如CentOS 7。 1. **RabbitMQ基础...
通过命令 brew install rabbitmq 安装时下载 rabbitmq-server-generic-unix-3.8.3.tar.xz 失败?当前文件可通过放入 ~/Library/Caches/Homebrew/downloads 目录下,再次运行命令即可安装成功!
rabbitmq-server-3.8.0-1.el6.noarch.rpm安装包下载 使用命令安装:yum -y install rabbitmq-server-3.6.6-1.el6.noarch.rpm 启动rabbitmq服务: 前台运行:rabbitmq-server start (用户关闭连接后,自动结束进程) ...
这个压缩包“rabbitmq-server-mac-standalone-3.5.7.tar.gz”是专为MAC OS X操作系统设计的RabbitMQ服务器版本,支持10.6.4或更高版本。在本文中,我们将深入探讨RabbitMQ的核心概念、安装过程以及如何在MAC OS X上...
标题提到的"rabbitmq-server-3.8.3.exe"是RabbitMQ服务器的3.8.3版本安装程序,适用于64位操作系统。这个版本可能包含了一些新特性、性能优化以及对旧版本bug的修复。RabbitMQ每个新版本的发布都会带来一些改进,以...
最新版windows rabbitmq-server-3.9.5.exe最新版windows rabbitmq-server-3.9.5.exe