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

农村建设网站网站建设费用 业务宣传费

农村建设网站,网站建设费用 业务宣传费,中文网站制作,wordpress综合商城主题目录 一、场景引入 二、延迟队列的三种场景 1、死信队列TTL对队列进行延迟 2、创建通用延时消息死信队列 对消息延迟 3、使用rabbitmq的延时队列插件 x-delayed-message使用 父pom文件 pom文件 配置文件 config 生产者 消费者 结果 一、场景引入 我们知道可以通过TT…目录 一、场景引入 二、延迟队列的三种场景 1、死信队列TTL对队列进行延迟 2、创建通用延时消息死信队列 对消息延迟 3、使用rabbitmq的延时队列插件 x-delayed-message使用 父pom文件 pom文件 配置文件 config 生产者 消费者 结果 一、场景引入 我们知道可以通过TTL来对队列进行设置过期时间通过后置处理器MessagePostProcessor对消息进行设置过期时间 那么根据TTL及MessagePostProcessor机制可以处理关于延迟方面的问题。 比如秒杀之后给30分钟时间进行支付如果30分钟后没有支付订单取消。 比如餐厅订座,A用户早上8点预定的某家餐厅下午6点的座位,B用户中午12点预定的下午5点的座位根据场景我们需要的时先让B用户进行消费,然后A用户再消费;这时TTL和MessagePostProcessor延迟就已经不能满足订餐的场景了 因为TTL是对队列进行延迟,MessagePostProcessor是对消息进行延迟但是MessagePostProcessor对消息延迟是不能根据订座的时间去排序消费的 /*** 比如当我们发送第一个消息时延迟的时间时50s,而发送的第二个消息延迟时间是30s,虽然延迟30s的消息比延迟50s发送的晚* 但按照我们设想的情况,延迟30s的消息应该先消费;可是实际情况却不是这样,而是延迟50s的消息到达时间后 30s的才能消费!(队列先进先出)* 那这样此方式的不足就出现了!* 场景:* A用户和B用户预定餐厅,A用户先开始预定的,预定的是下午6点。B用户比A用户预定操作晚一些,但是B用户预定的时间是下午5点。通过此场景* 我们希望的是B用户先进行用餐(因为他预定的吃饭时间比A早一些,需要先安排吃饭。不能说A用户没到6点B用户预定5点的吃不了。),根据此* 场景 之前的队列延迟还是消息延迟都不能满足场景需求了,这样就需要另一种延迟方式进行解决了! -使用rabbitmq的延时队列插件*//*** 注意* TTL是对队列进行延迟,只要是在此队列中的消息都会按照TTL设置时间进行延迟;* MessagePostProcessor是对消息进行延迟;** 如果我们不仅使用了消息延迟,而且还使用了队列延迟,那么延迟的时间就会以小的时间为准!* 理解:* 如果a消息设置的消息延迟是30s,b消息设置的延迟时间是90s,队列设置的延迟是60s。那么a消息最终的延迟是30s(a的消息延迟与队列延迟* 比对以延迟时间小的为准),b消息最终延迟的时间是60s(b的消息延迟与队列延迟比对以延迟的时间小的为准)*/ 二、延迟队列的三种场景 1、死信队列TTL对队列进行延迟 给队列设置TTL过期时间此队列可不用绑定消费者,时间到后把消息投递到死信队列中由死信队列的消费者进行消费,这样就能达到延迟消费的作用 Beanpublic Queue directQueueLong(){return QueueBuilder.durable(业务队列名称).deadLetterExchange(死信交换机名称).deadLetterRoutingKey(死信队列 RoutingKey).ttl(20000) // 消息停留时间//.maxLength(500).build();}监听死信队列即可处理超时的消息队列 缺点 上述实现方式中ttl延时队列中所有的消息超时时间都是一样的如果不同消息想设置不一样的超时时间就需要建立多个不同超时时间的消息队列比较麻烦且不利于维护。 2、创建通用延时消息死信队列 对消息延迟 这样的方式可对每一个消息设置指定的过期时间,不用像TTL那样给队列设置过期时间(若队列设置的过期时间达到后其队列中的消息均会被删除或别的处理)但是由于队列是先进先出,若先投递的消息设置的过期时间是40s,后投递的消息过期时间是30s那么设置过期时间为30s的并不会到30s时就投递到死信队列中,而是等40s到期后才会一起被投递。 rabbitTemplate.convertAndSend(交换机名称, RoutingKey,对象, message {message.getMessageProperties().setExpiration(String.valueOf(5000))// 设置消息的持久化属性//这样发送的消息就会被持久化到 RabbitMQ 中即使 RabbitMQ 重启消息也不会丢失。 message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);return message;}); 缺点 该种方式可以创建一个承载不同超时时间消息的消息队列但是这种方式有一个问题如果消息队列中排在前面的消息没有到超时时间即使后面的消息到了超时时间先到超时时间的消息也不会进入死信队列而是先检查排在最前面的消息队列是否到了超时时间如果到了超时时间才会继续检查后面的消息。 3、使用rabbitmq的延时队列插件 使用rabbitmq的延时队列插件实现同一个队列中有多个不同超时时间的消息并按时间超时顺序出队 1、下载延迟插件 在 RabbitMQ 的 3.5.7 版本之后提供了一个插件rabbitmq-delayed-message-exchange来实现延迟队列 同时需保证 Erlang/OPT 版本为 18.0 之后。 下载地址 https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases 2、安装插件并启用 下载完成后直接把插件放在 /home/rabbitmq 目录然后拷贝到容器内plugins目录下my-rabbit是容器的name也可以使用容器id docker cp /home/rabbitmq/rabbitmq_delayed_message_exchange-3.12.0.ez rabbitmq:/plugins 进入 Docker 容器 docker exec -it rabbit /bin/bash 在plugins内启用插件 rabbitmq-plugins enable rabbitmq_delayed_message_exchange 退出容器 exit 重启 RabbitMQ docker restart my-rabbit 貌似不重启也能生效 结果 就多了一个x-delayed-message交换机 x-delayed-message使用 父pom文件 ?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 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.7.1/version !-- version2.2.5.RELEASE/version--relativePath/ !-- lookup parent from repository --/parentgroupIdcom.chensir/groupIdartifactIdspring-boot-rabbitmq/artifactIdversion0.0.1-SNAPSHOT/versionnamespring-boot-rabbitmq/namepropertiesjava.version8/java.versionhutool.version5.8.3/hutool.versionlombok.version1.18.24/lombok.version/propertiesdescriptionspring-boot-rabbitmq/descriptionpackagingpom/packagingmodulesmoduledirect-exchange/modulemodulefanout-exchange/modulemoduletopic-exchange/modulemodulegame-exchange/modulemoduledead-letter-queue/modulemoduledelay-queue/modulemoduledelay-queue2/module/modulesdependencyManagementdependenciesdependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion${hutool.version}/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion${lombok.version}/version/dependency/dependencies/dependencyManagement/projectpom文件 ?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 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.chensir/groupIdartifactIdspring-boot-rabbitmq/artifactIdversion0.0.1-SNAPSHOT/versionrelativePath../pom.xml /relativePath/parentartifactIddelay-queue2/artifactIddependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-amqp/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.springframework.amqp/groupIdartifactIdspring-rabbit-test/artifactIdscopetest/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project配置文件 logging.level.com.chensir debug server.port8086 #host spring.rabbitmq.host121.40.100.66 #默认5672 spring.rabbitmq.port5672 #用户名 spring.rabbitmq.usernameguest #密码 spring.rabbitmq.passwordguest #连接到代理时用的虚拟主机 spring.rabbitmq.virtual-host/ #每个消费者每次可最大处理的nack消息数量 spring.rabbitmq.listener.simple.prefetch1 #表示消息确认方式其有三种配置方式分别是none、manual(手动)和auto(自动)默认auto spring.rabbitmq.listener.simple.acknowledge-modeauto #监听重试是否可用 spring.rabbitmq.listener.simple.retry.enabledtrue #最大重试次数 spring.rabbitmq.listener.simple.retry.max-attempts5 #最大重试时间间隔 spring.rabbitmq.listener.simple.retry.max-interval3000ms #第一次和第二次尝试传递消息的时间间隔 spring.rabbitmq.listener.simple.retry.initial-interval1000ms #应用于上一重试间隔的乘数 spring.rabbitmq.listener.simple.retry.multiplier2 #决定被拒绝的消息是否重新入队默认是true与参数acknowledge-mode有关系 spring.rabbitmq.listener.simple.default-requeue-rejectedfalseconfig package com.chensir.config;import org.springframework.amqp.core.*; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;import java.util.HashMap; import java.util.Map;Configuration public class RabbitConfig {Beanpublic MessageConverter messageConverter(){return new Jackson2JsonMessageConverter();}Beanpublic CustomExchange customExchange(){MapString,Object args new HashMap();//延迟时以direct直连方式绑定args.put(x-delayed-type,direct);// name:交换机名称 type:类型 固定值x-delayed-messagereturn new CustomExchange(chen-x-delayedExchange,x-delayed-message,true,false,args);}Beanpublic Queue directQueueLong(){return QueueBuilder.durable(chen-DirectQueue).build();}Beanpublic Binding binding(){return BindingBuilder.bind(directQueueLong()).to(customExchange()).with(direct123).noargs();} } 生产者 package com.chensir.provider;import com.chensir.model.OrderIngOk; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Component;import javax.annotation.Resource;Component Slf4j public class DirectProvider {Resourceprivate RabbitTemplate rabbitTemplate;public void send(){OrderIngOk orderIngOk new OrderIngOk();orderIngOk.setOrderNo(202207149687-1);orderIngOk.setId(1);orderIngOk.setUserName(倪海杉前-延迟40秒);rabbitTemplate.convertAndSend(chen-x-delayedExchange, direct123,orderIngOk,m-{m.getMessageProperties().setDelay(40*1000); //设置延迟时间对延迟交换机有效// m.getMessageProperties().setExpiration(String.valueOf(30*1000)); 设置过期时间对队列有效return m;});OrderIngOk orderIngOk2 new OrderIngOk();orderIngOk2.setOrderNo(202207149687-2);orderIngOk2.setId(2);orderIngOk2.setUserName(倪海杉后-延迟30秒);rabbitTemplate.convertAndSend(chen-x-delayedExchange, direct123,orderIngOk2,m-{m.getMessageProperties().setDelay(30*1000);return m;});log.debug(消息生产完成);}}消费者 package com.chensir.consumer;import cn.hutool.json.JSONUtil; import com.chensir.model.OrderIngOk; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component;import java.io.IOException;Component Slf4j public class DirectConsumer {RabbitHandlerRabbitListener(queues chen-DirectQueue )public void process(OrderIngOk orderIngOk) throws IOException {try {// 处理业务开始log.debug(接受到消息,并正常处理结束,{}, JSONUtil.toJsonStr(orderIngOk));// 处理业务结束} catch (Exception ex){throw ex;}} } 结果 2023-08-29 18:27:45.983 DEBUG 15568 --- [ main] com.chensir.provider.DirectProvider : 消息生产完成 2023-08-29 18:28:16.143 DEBUG 15568 --- [ntContainer#0-1] com.chensir.consumer.DirectConsumer : 接受到消息,并正常处理结束,{id:2,OrderNo:202207149687-2,userName:倪海杉后-延迟30秒} 2023-08-29 18:28:26.057 DEBUG 15568 --- [ntContainer#0-1] com.chensir.consumer.DirectConsumer : 接受到消息,并正常处理结束,{id:1,OrderNo:202207149687-1,userName:倪海杉前-延迟40秒}可见 延迟40s的是先发送的但是最终结果是先消费延迟30s的。这样就能达到我们订座的场景需求了。
文章转载自:
http://www.morning.hxljc.cn.gov.cn.hxljc.cn
http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn
http://www.morning.qgkcs.cn.gov.cn.qgkcs.cn
http://www.morning.kflpf.cn.gov.cn.kflpf.cn
http://www.morning.yrycb.cn.gov.cn.yrycb.cn
http://www.morning.mgnrc.cn.gov.cn.mgnrc.cn
http://www.morning.zsfooo.com.gov.cn.zsfooo.com
http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn
http://www.morning.hmhdn.cn.gov.cn.hmhdn.cn
http://www.morning.jqtb.cn.gov.cn.jqtb.cn
http://www.morning.qfgxk.cn.gov.cn.qfgxk.cn
http://www.morning.dpmkn.cn.gov.cn.dpmkn.cn
http://www.morning.zlxrg.cn.gov.cn.zlxrg.cn
http://www.morning.wqpr.cn.gov.cn.wqpr.cn
http://www.morning.cwgpl.cn.gov.cn.cwgpl.cn
http://www.morning.wbqk.cn.gov.cn.wbqk.cn
http://www.morning.gnzsd.cn.gov.cn.gnzsd.cn
http://www.morning.csxlm.cn.gov.cn.csxlm.cn
http://www.morning.skqfx.cn.gov.cn.skqfx.cn
http://www.morning.lqznq.cn.gov.cn.lqznq.cn
http://www.morning.nhzxd.cn.gov.cn.nhzxd.cn
http://www.morning.wnnts.cn.gov.cn.wnnts.cn
http://www.morning.kdbcx.cn.gov.cn.kdbcx.cn
http://www.morning.dmlsk.cn.gov.cn.dmlsk.cn
http://www.morning.wwdlg.cn.gov.cn.wwdlg.cn
http://www.morning.zwzlf.cn.gov.cn.zwzlf.cn
http://www.morning.jgncd.cn.gov.cn.jgncd.cn
http://www.morning.qgghr.cn.gov.cn.qgghr.cn
http://www.morning.xqkjp.cn.gov.cn.xqkjp.cn
http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn
http://www.morning.fwcjy.cn.gov.cn.fwcjy.cn
http://www.morning.djgrg.cn.gov.cn.djgrg.cn
http://www.morning.zfrs.cn.gov.cn.zfrs.cn
http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn
http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn
http://www.morning.fykqh.cn.gov.cn.fykqh.cn
http://www.morning.ykbgs.cn.gov.cn.ykbgs.cn
http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn
http://www.morning.gskzy.cn.gov.cn.gskzy.cn
http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn
http://www.morning.wbfly.cn.gov.cn.wbfly.cn
http://www.morning.fwnyz.cn.gov.cn.fwnyz.cn
http://www.morning.rqbkc.cn.gov.cn.rqbkc.cn
http://www.morning.nrpp.cn.gov.cn.nrpp.cn
http://www.morning.hqwtm.cn.gov.cn.hqwtm.cn
http://www.morning.mxhys.cn.gov.cn.mxhys.cn
http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn
http://www.morning.pbygt.cn.gov.cn.pbygt.cn
http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn
http://www.morning.qbjrf.cn.gov.cn.qbjrf.cn
http://www.morning.zffps.cn.gov.cn.zffps.cn
http://www.morning.kwqt.cn.gov.cn.kwqt.cn
http://www.morning.rttp.cn.gov.cn.rttp.cn
http://www.morning.skbhl.cn.gov.cn.skbhl.cn
http://www.morning.ddjp.cn.gov.cn.ddjp.cn
http://www.morning.hzryl.cn.gov.cn.hzryl.cn
http://www.morning.nlzpj.cn.gov.cn.nlzpj.cn
http://www.morning.yxmcx.cn.gov.cn.yxmcx.cn
http://www.morning.kgxyd.cn.gov.cn.kgxyd.cn
http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn
http://www.morning.qpsdq.cn.gov.cn.qpsdq.cn
http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn
http://www.morning.tbkqs.cn.gov.cn.tbkqs.cn
http://www.morning.cpzkq.cn.gov.cn.cpzkq.cn
http://www.morning.sgfnx.cn.gov.cn.sgfnx.cn
http://www.morning.mnkz.cn.gov.cn.mnkz.cn
http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn
http://www.morning.wrqw.cn.gov.cn.wrqw.cn
http://www.morning.clndl.cn.gov.cn.clndl.cn
http://www.morning.rwcw.cn.gov.cn.rwcw.cn
http://www.morning.hclplus.com.gov.cn.hclplus.com
http://www.morning.rzpkt.cn.gov.cn.rzpkt.cn
http://www.morning.yymlk.cn.gov.cn.yymlk.cn
http://www.morning.kdnbf.cn.gov.cn.kdnbf.cn
http://www.morning.kaylyea.com.gov.cn.kaylyea.com
http://www.morning.ffwrq.cn.gov.cn.ffwrq.cn
http://www.morning.hgscb.cn.gov.cn.hgscb.cn
http://www.morning.taipinghl.cn.gov.cn.taipinghl.cn
http://www.morning.bnqcm.cn.gov.cn.bnqcm.cn
http://www.morning.ppbqz.cn.gov.cn.ppbqz.cn
http://www.tj-hxxt.cn/news/275366.html

相关文章:

  • 京东联盟的网站怎么做沈阳快速网站建设网站开发
  • 网页预览手机网站效果音乐网站可做哪些内容
  • 玉环 企业网站建设wordpress 翻译语言
  • 适合推广的网站中国免费网站服务器
  • 呼和浩特企业网站建设招聘海报制作软件app免费
  • 做淘宝网站要求与想法公网ip购买
  • 定制做网站费用江苏省住房城乡建设厅官方网站
  • 毕业设计网站建设选题依据江苏市场监督管理局
  • 网站空间费wordpress 边框插件
  • 网站开发都用什么语言如何将优酷视频上传到自己网站
  • 网站搜索推广销售广州app定制开发
  • 网页游戏的网站wordpress $memcached_servers
  • 网站建设费用预算明细西宁做网站建设公司哪家好
  • 网站建设是什么科目分公司注册流程网上注册
  • 云建站哪家好哈尔滨建设工程造价信息网
  • 网站风格变化一个做网站编程的条件
  • 北京企业做网站报价广西建设主管部门网站
  • 免费网站制作o2o网站设计方案
  • 建设做网站wordpress 文件
  • 腾讯空间个人认证 企业认证 网站认证哪种功能用途最齐全??网站编辑教程
  • 网站建设对电子商务的作用海外营销是干什么的
  • 电动门 东莞网站建设建设外贸网站要多少钱
  • 企业为什么要建网站做图赚钱的网站
  • 做电商一件代发的网站泰州网站建设定制
  • seo 网站两个ip服务 好的网站制作
  • 网站建设 朝阳区一元购网站建设方案书
  • 会员网站建设在线电影视频wordpress主题
  • net快速建站音乐网站如何建立
  • 西安门户网站开发化德网站建设
  • 馆陶网站汉化插件wordpress