import java.util.HashMap;/** * @Description : rabbit配置 * @Author : cxw * @Date : 2022/11/15 13:39 * @Version : 1.0 **/@ConfigurationpublicclassRabbitMQUtils {privateHashMap<String,Queue> queueHashMap=newHashMap<>(); @AutowiredprivateAmqpAdmin amqpAdmin; @AutowiredprivateRabbitTemplate ...
RabbitMQUtils.close(channel, connection); } } packagecom.nijunyang.rabbitmq.limit;importcom.nijunyang.rabbitmq.util.RabbitMQUtils;importcom.rabbitmq.client.*;importorg.springframework.util.StringUtils;importjava.io.IOException;importjava.util.concurrent.TimeoutException;/*** Description: * Created b...
3、RabbitUtils public class RabbitUtils { private static final Logger logger = LoggerFactory.getLogger(RabbitUtils.class); public static void sendModifyRemakeNameMsg(RabbitTemplate rabbitTemplate, RabbitFriend rabbitFriend){ try{ if(rabbitFriend.getLists().size() < 1){ return; } logger.info("sen...
一、创建工具类 package com.zzuli.rabbitmq.utils; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; /** * @Author WangXiaoSong * @Date 2023/4/11 21:42 * @Description 此类为连接工厂创建信道的工具类 */ public class Rabbit...
上述消息生产者和消费者获取创建ConnectionFactory,获取Connection和Channel的过程是一样的,我们可以封装成一个工具类RabbitMqUtils。 packageutils;importcom.rabbitmq.client.Channel;importcom.rabbitmq.client.Connection;importcom.rabbitmq.client.ConnectionFactory;publicclassRabbitMqUtils{// 获得RabbitMQ连接的channelpub...
{Channelchannel=RabbitMqUtils.createChannel();//生产者发送消息,将消息设置为TTL消息AMQP.BasicPropertiesproperties=newAMQP.BasicProperties().builder().expiration("10000").build();for(inti=0;i<10;i++){Stringmessage=i+"";channel.basicPublish(Consumer01.EXCHANGE_DIRECT,"routingkey_direct",...
packagecom.qfedu.mq.service;importcom.qfedu.mq.utils.ConnectionUtil;importcom.rabbitmq.client.Channel;importcom.rabbitmq.client.Connection;publicclassSendMsg{publicstaticvoidmain(String[]args)throwsException{Stringmsg="Hello HuangDaoJun!";Connectionconnection=ConnectionUtil.getConnection();Channelchannel=connect...
public class Consumer01 {//普通交换机名称private static final String NORMAL_EXCHANGE = "normal_exchange";//死信交换机名称private static final String DEAD_EXCHANGE = "dead_exchange";public static void main(String[] args) throws Exception {Channel channel = RabbitMqUtils.getChannel();//声明死信和...
packagetest;importcom.rabbitmq.client.*;importutils.RabbitMQUtils;importjava.io.IOException;publicclassCustomer1{publicstaticvoidmain(String[]args){Connection connect=RabbitMQUtils.getConnect();try{//1、获取信道assert connect!=null;Channel channel=connect.createChannel();//2、声明队列,与生产者队列保持...
publicclassWorker01{// 队列名称publicstaticfinal StringQUEUE_NAME="hello";// 接受消息publicstaticvoidmain(String[]args)throws IOException,TimeoutException{Channel channel=RabbitMqUtils.getInstance().getChannel();// 声明 接受消息DeliverCallback deliverCallback=(consumerTag,message)->{System.out.println...