JAVA全系列 教程
3762个小节阅读:7092.5k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
接下来我们编写通配符模式的生产者:
xxxxxxxxxx
// 生产者
public class Producer {
public static void main(String[] args) throws IOException, TimeoutException {
// 1.创建连接工厂
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost("192.168.0.162");
connectionFactory.setPort(5672);
connectionFactory.setUsername("itbaizhan");
connectionFactory.setPassword("itbaizhan");
connectionFactory.setVirtualHost("/");
// 2.创建连接
Connection connection = connectionFactory.newConnection();
// 3.建立信道
Channel channel = connection.createChannel();
// 4.创建交换机
channel.exchangeDeclare("exchange_topic", BuiltinExchangeType.TOPIC,true);
// 5.创建队列
channel.queueDeclare("SEND_MAIL3",true,false,false,null);
channel.queueDeclare("SEND_MESSAGE3",true,false,false,null);
channel.queueDeclare("SEND_STATION3",true,false,false,null);
// 6.交换机绑定队列
channel.queueBind("SEND_MAIL3","exchange_topic","#.mail.#");
channel.queueBind("SEND_MESSAGE3","exchange_topic","#.message.#");
channel.queueBind("SEND_STATION3","exchange_topic","#.station.#");
// 7.发送消息
channel.basicPublish("exchange_topic","mail.message.station",null,
"双十一大促活动".getBytes());
channel.basicPublish("exchange_topic","station",null,
"小型促销活动".getBytes());
// 8.关闭资源
channel.close();
connection.close();
}
}
实时效果反馈
1. RabbitMQ通配符模式发送消息时,消息的的特点为
A 由一个单词构成
B 由多个单词构成,中间以.
分割
C 由多个单词构成,中间以_
分割
D 由多个单词构成,中间以,
分割
2. RabbitMQ通配符模式使用的交换机为
A direct
B fanout
C routing
D topic
答案
1=>B 2=>D