96SEO 2026-02-19 17:03 0
1、RabbitMQ死信队列2、代码示例2.1、队列过期2.1.1、配置类RabbitConfig关键代码2.1.2、业务类MessageService2.1.3、配置文件application.yml2.1.4、启动类2.1.5、配置文件2.1.6、测试

2.2、消息过期2.2.1、配置类RabbitConfig2.2.2、业务类MessageService关键代码2.2.3、配置文件application.yml2.2.4、启动类同上2.2.5、配置文件同上2.2.6、测试
2.3、队列达到最大长度先入队的消息会被发送到DLX2.3.1、配置类RabbitConfig关键代码2.3.2、业务类MessageService关键代码2.3.3、配置文件application.yml2.3.4、启动类同上2.3.5、配置文件pom.xml同上2.3.6、测试
2.4、消费者拒绝消息不进行重新投递2.4.1、生产者2.4.1.1、生产者application.yml2.4.1.2、生产者发送消息2.4.1.3、生产者配置类
2.4.2、消费者2.4.2.1、消费者application.yml
org.springframework.amqp.core.*;
org.springframework.beans.factory.annotation.Value;
org.springframework.context.annotation.Bean;
org.springframework.context.annotation.Configuration;import
{Value(${my.exchangeNormalName})private
exchangeNormalName;Value(${my.queueNormalName})private
queueNormalName;Value(${my.exchangeDlxName})private
exchangeDlxName;Value(${my.queueDlxName})private
ExchangeBuilder.directExchange(exchangeNormalName).build();}/***
HashMap();arguments.put(x-message-ttl,20000);//设置队列的过期时间为20秒//重点设置这两个参数arguments.put(x-dead-letter-exchange,exchangeDlxName);
//设置队列的死信交换机arguments.put(x-dead-letter-routing-key,error);//设置死信路由key要跟死信交换机和死信队列绑定的路由key一致return
QueueBuilder.durable(queueNormalName).withArguments(arguments)
BindingBuilder.bind(normalQueue).to(normalExchange).with(order);}/***
ExchangeBuilder.directExchange(exchangeDlxName).build();}/***
QueueBuilder.durable(queueDlxName).build();}/***
BindingBuilder.bind(dlxQueue).to(dlxExchange).with(error);}
org.springframework.amqp.core.Message;
org.springframework.amqp.core.MessageBuilder;
org.springframework.amqp.rabbit.core.RabbitTemplate;
org.springframework.context.annotation.Bean;
org.springframework.stereotype.Service;import
world.getBytes()).build();rabbitTemplate.convertAndSend(exchange.normal.a,order,message);log.info(消息发送完毕发送时间是new
#正常队列没有消费组设置过期时间exchangeDlxName:
com.power.service.MessageService;
org.springframework.boot.ApplicationArguments;
org.springframework.boot.ApplicationRunner;
org.springframework.boot.SpringApplication;
org.springframework.boot.autoconfigure.SpringBootApplication;import
javax.annotation.Resource;SpringBootApplication
{SpringApplication.run(Application.class);}Overridepublic
xmlnshttp://maven.apache.org/POM/4.0.0
xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.power/groupIdartifactIdrabbit_06_dlx01/artifactIdversion1.0-SNAPSHOT/versionnamerabbit_06_dlx01/namepropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.6.13/versionrelativePath//parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.24/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-amqp/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project2.1.6、测试
消息会先被发送到正常队列queue.normal.a中超时未被消费
org.springframework.amqp.core.*;
org.springframework.beans.factory.annotation.Value;
org.springframework.context.annotation.Bean;
org.springframework.context.annotation.Configuration;import
{Value(${my.exchangeNormalName})private
exchangeNormalName;Value(${my.queueNormalName})private
queueNormalName;Value(${my.exchangeDlxName})private
exchangeDlxName;Value(${my.queueDlxName})private
ExchangeBuilder.directExchange(exchangeNormalName).build();}/***
HashMap();//重点设置这两个参数//设置队列的死信交换机arguments.put(x-dead-letter-exchange,exchangeDlxName);//设置死信路由key要跟死信交换机和死信队列绑定的路由key一致arguments.put(x-dead-letter-routing-key,error);return
QueueBuilder.durable(queueNormalName).withArguments(arguments)
BindingBuilder.bind(normalQueue).to(normalExchange).with(order);}/***
ExchangeBuilder.directExchange(exchangeDlxName).build();}/***
QueueBuilder.durable(queueDlxName).build();}/***
BindingBuilder.bind(dlxQueue).to(dlxExchange).with(error);}
org.springframework.amqp.core.Message;
org.springframework.amqp.core.MessageBuilder;
org.springframework.amqp.core.MessageProperties;
org.springframework.amqp.rabbit.core.RabbitTemplate;
org.springframework.context.annotation.Bean;
org.springframework.stereotype.Service;import
MessageProperties();//设置单条消息的过期时间单位为毫秒数据类型为字符串messageProperties.setExpiration(20000);Message
world.getBytes()).andProperties(messageProperties).build();rabbitTemplate.convertAndSend(exchange.normal.02,order,message);}catch
e){e.printStackTrace();log.info(消息发送失败new
Date());}log.info(消息发送完毕发送时间是new
#正常队列没有消费组设置过期时间exchangeDlxName:
org.springframework.amqp.core.*;
org.springframework.beans.factory.annotation.Value;
org.springframework.context.annotation.Bean;
org.springframework.context.annotation.Configuration;import
{Value(${my.exchangeNormalName})private
exchangeNormalName;Value(${my.queueNormalName})private
queueNormalName;Value(${my.exchangeDlxName})private
exchangeDlxName;Value(${my.queueDlxName})private
ExchangeBuilder.directExchange(exchangeNormalName).build();}/***
HashMap();//设置队列的最大长度arguments.put(x-max-length,5);//重点设置这两个参数//设置队列的死信交换机arguments.put(x-dead-letter-exchange,exchangeDlxName);//设置死信路由key要跟死信交换机和死信队列绑定的路由key一致arguments.put(x-dead-letter-routing-key,error);return
QueueBuilder.durable(queueNormalName).withArguments(arguments)
BindingBuilder.bind(normalQueue).to(normalExchange).with(order);}/***
ExchangeBuilder.directExchange(exchangeDlxName).build();}/***
QueueBuilder.durable(queueDlxName).build();}/***
BindingBuilder.bind(dlxQueue).to(dlxExchange).with(error);}
org.springframework.amqp.core.Message;
org.springframework.amqp.core.MessageBuilder;
org.springframework.amqp.rabbit.core.RabbitTemplate;
org.springframework.context.annotation.Bean;
org.springframework.stereotype.Service;import
MessageBuilder.withBody(msg.getBytes()).build();rabbitTemplate.convertAndSend(exchange.normal.03,order,message);log.info(消息发送完毕发送时间是new
#正常队列没有消费组设置过期时间exchangeDlxName:
消费者从正常的队列接收消息但是消费者对消息不进行确认并且不对消息进行重新投递此时消息就进入死信队列。
#正常队列没有消费组设置过期时间exchangeDlxName:
org.springframework.amqp.core.Message;
org.springframework.amqp.core.MessageBuilder;
org.springframework.amqp.rabbit.core.RabbitTemplate;
org.springframework.context.annotation.Bean;
org.springframework.stereotype.Service;import
MessageBuilder.withBody(msg.getBytes()).build();rabbitTemplate.convertAndSend(exchange.normal.04,order,message);log.info(消息发送完毕发送时间是new
org.springframework.amqp.core.*;
org.springframework.beans.factory.annotation.Value;
org.springframework.context.annotation.Bean;
org.springframework.context.annotation.Configuration;import
{Value(${my.exchangeNormalName})private
exchangeNormalName;Value(${my.queueNormalName})private
queueNormalName;Value(${my.exchangeDlxName})private
exchangeDlxName;Value(${my.queueDlxName})private
ExchangeBuilder.directExchange(exchangeNormalName).build();}/***
HashMap();//重点设置这两个参数//设置队列的死信交换机arguments.put(x-dead-letter-exchange,exchangeDlxName);//设置死信路由key要跟死信交换机和死信队列绑定的路由key一致arguments.put(x-dead-letter-routing-key,error);return
QueueBuilder.durable(queueNormalName).withArguments(arguments)
BindingBuilder.bind(normalQueue).to(normalExchange).with(order);}/***
ExchangeBuilder.directExchange(exchangeDlxName).build();}/***
QueueBuilder.durable(queueDlxName).build();}/***
BindingBuilder.bind(dlxQueue).to(dlxExchange).with(error);}
powerlistener:simple:acknowledge-mode:
org.springframework.amqp.core.Message;
org.springframework.amqp.core.MessageProperties;
org.springframework.amqp.rabbit.annotation.RabbitListener;
org.springframework.stereotype.Component;import
{RabbitListener(queues{queue.normal.04})public
channel){//获取消息属性MessageProperties
message.getMessageProperties();//获取消息的唯一标识类似学号和身份证号long
messageProperties.getDeliveryTag();try{byte[]
String(body);log.info(监听到的消息是msg,接收的时间是new
a1/0;//消费者的手动确认false只确认当前消息true批量确认channel.basicAck(deliveryTag,false);}catch
e){log.error(接收者出现问题{},e.getMessage());try
channel.basicNack(deliveryTag,false,true);//消费者的手动不确认参数3false
不重新入队不重新投递就会变成死信channel.basicNack(deliveryTag,false,false);}catch
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback