当前位置: 首页 > news >正文

中文网站建设小组企业应加强自身网站建设

中文网站建设小组,企业应加强自身网站建设,邢台学校网站建设价格,免费做网站软件视频RabbitMQ设置消息过期时间 1、过期消息#xff08;死信#xff09;2、设置消息过期的两种方式2.1、设置单条消息的过期时间2.1.1、配置文件application.yml2.1.2、配置类RabbitConfig2.1.3、发送消息业务类service#xff08;核心代码#xff09;2.1.4、启动类2.1.5、依赖文… RabbitMQ设置消息过期时间 1、过期消息死信2、设置消息过期的两种方式2.1、设置单条消息的过期时间2.1.1、配置文件application.yml2.1.2、配置类RabbitConfig2.1.3、发送消息业务类service核心代码2.1.4、启动类2.1.5、依赖文件pom.xml2.1.6、测试 2.2、通过队列属性设置消息过期时间2.1.1、配置文件application.yml2.1.2、配置类RabbitConfig核心代码2.2.3、发送消息业务类service2.2.4、启动类2.2.5、依赖文件pom.xml2.2.6、测试 1、过期消息死信 过期消息也叫TTL消息TTLTime To Live 消息的过期时间有两种设置方式设置单条消息的过期时间和通过队列属性设置消息过期时间 2、设置消息过期的两种方式 队列的过期时间决定了在没有任何消费者的情况下队列中的消息可以存活多久 注意事项如果消息和对列都设置过期时间则消息的TTL以两者之间较小的那个数值为准。 2.1、设置单条消息的过期时间 2.1.1、配置文件application.yml server:port: 8080 spring:application:name: ttl-test01rabbitmq:host: 你的服务器IPport: 5672username: 你这账号password: 你的密码virtual-host: powermy:exchangeName: exchange.ttl.aqueueName: queue.ttl.a2.1.2、配置类RabbitConfig package com.power.config;import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class RabbitConfig {Value(${my.exchangeName})private String exchangeName;Value(${my.queueName})private String queueName;//创建交换机Beanpublic DirectExchange directExchange(){return ExchangeBuilder.directExchange(exchangeName).build();}//创建队列Beanpublic Queue queue(){return QueueBuilder.durable(queueName).build();}Beanpublic Binding binding(DirectExchange exchangeName,Queue queueName){return BindingBuilder.bind(queueName).to(exchangeName).with(info);} }2.1.3、发送消息业务类service核心代码 package com.power.service;import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageBuilder; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Service;import javax.annotation.Resource; import java.util.Date;Service Slf4j public class MessageService {Resourceprivate RabbitTemplate rabbitTemplate;Beanpublic void sendMsg(){//设置消息过期的核心代码MessageProperties messageProperties new MessageProperties();messageProperties.setExpiration(30000);//设置消息过期时间Message message MessageBuilder.withBody(hello world.getBytes()).andProperties(messageProperties).build();rabbitTemplate.convertAndSend(exchange.ttl.a,info,message);log.info(消息发送完毕发送时间是new Date());} }2.1.4、启动类 package com.power;import com.power.service.MessageService; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;import javax.annotation.Resource;SpringBootApplication public class Application implements ApplicationRunner {Resourceprivate MessageService messageService;public static void main(String[] args) {SpringApplication.run(Application.class);}Overridepublic void run(ApplicationArguments args) throws Exception {messageService.sendMsg();} }2.1.5、依赖文件pom.xml ?xml version1.0 encodingUTF-8? project 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_05_ttl01/artifactIdversion1.0-SNAPSHOT/versionnamerabbit_05_ttl01/name!-- FIXME change it to the projects website --urlhttp://www.example.com/urlpropertiesmaven.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、测试 启动项目 登录rabbitmq后台 在消息有效期内可以获取到消息。 超过消息有效期获取不到消息。 2.2、通过队列属性设置消息过期时间 2.1.1、配置文件application.yml server:port: 8080 spring:application:name: ttl-test02rabbitmq:host: 你的服务器IPport: 5672username: 你这账号password: 你的密码virtual-host: powermy:exchangeName: exchange.ttl.bqueueName: queue.ttl.b2.1.2、配置类RabbitConfig核心代码 package com.power.config;import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;import java.util.HashMap; import java.util.Map;Configuration public class RabbitConfig {Value(${my.exchangeName})private String exchangeName;Value(${my.queueName})private String queueName;//创建交换机Beanpublic DirectExchange directExchange(){return ExchangeBuilder.directExchange(exchangeName).build();}//创建队列Beanpublic Queue queue(){//设置队列消息的过期时间超过这个有效期队列内的所有消息都会过期//方式1new Queue的方式MapString, Object arguments new HashMap();arguments.put(x-message-ttl,30000);return new Queue(queueName,true,false,false,arguments);// 方式2建造者方式 // return QueueBuilder.durable(queueName).withArguments(arguments).build();}Beanpublic Binding binding(DirectExchange exchangeName,Queue queueName){return BindingBuilder.bind(queueName).to(exchangeName).with(info);} }2.2.3、发送消息业务类service package com.power.service;import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageBuilder; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Service;import javax.annotation.Resource; import java.util.Date;Service Slf4j public class MessageService {Resourceprivate RabbitTemplate rabbitTemplate;Beanpublic void sendMsg(){Message message MessageBuilder.withBody(hello world.getBytes()).build();rabbitTemplate.convertAndSend(exchange.ttl.b,info,message);log.info(消息发送完毕发送时间是new Date());} }2.2.4、启动类 package com.power;import com.power.service.MessageService; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;import javax.annotation.Resource;SpringBootApplication public class Application implements ApplicationRunner {Resourceprivate MessageService messageService;public static void main(String[] args) {SpringApplication.run(Application.class);}Overridepublic void run(ApplicationArguments args) throws Exception {messageService.sendMsg();} }2.2.5、依赖文件pom.xml ?xml version1.0 encodingUTF-8? project 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_05_ttl02/artifactIdversion1.0-SNAPSHOT/versionnamerabbit_05_ttl02/name!-- FIXME change it to the projects website --urlhttp://www.example.com/urlpropertiesmaven.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.2.6、测试 启动项目 登录后台查看
http://www.dnsts.com.cn/news/11898.html

相关文章:

  • 潍坊市坊子区建设局网站网易企业邮箱app叫什么名字
  • jquery 单页网站网站用的什么字体
  • 免费做网站的问题谷歌镜像网站怎么做
  • 王店镇建设中学网站汉中公司做网站
  • 陕西网站开发价格不懂网站建设.怎么销售
  • 网站logo如何修改wordpress文章采集
  • 装饰网站建设策划书wordpress安装字体
  • 在线电影网站建设开发公司承担物业费的规定
  • 天津公司网站怎样制作本机iis发布网站后台管理
  • 好看 大气的网站链接缩短生成器
  • 怎么免费建设金融网站物流网站建设的背景
  • 学校网站建设分析做外贸的都有那些网站
  • 外贸网站设计风格公司注册网站入口
  • 滨州网站网站建设自己怎么做网址开网站
  • 有哪些可以做图的网站啊优质企业网站建设
  • 鄂州英文网站建设竞价托管魏大帅
  • 杭州如何设计公司网站做模板的软件
  • 怎么样申请网站域名深圳宝安中心区
  • 孝感做网站xgsh遵义网站搭建公司哪家好
  • 录音录像手表网站wordpress 拓展
  • 哪个网站可以做照片分享标杆建设网站
  • 大连模板网站制作费用陵园网站建设价格
  • 找建设网站咋建网站
  • 请详细说明网站开发流程及原则昆明做整站优化
  • 精美网站设计欣赏网站建设常出现的问题
  • 网站图标ico 设置专业微网站建设公司首选公司哪家好
  • 网站维护的协议开发一个个人网站
  • 高端设计网站制作中国政务网站建设绩效评估
  • 在线玩网页游戏h5网站大全商城开发平台
  • 太原制作响应式网站刘强东自己做网站