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

搜索平台山东服务好的seo公司

搜索平台,山东服务好的seo公司,湖南怀化市住房城乡建设局网站,中国建设银行员工网站RabbitMQ消息的可靠性 一 生产者的可靠性 生产者重试 有时候由于网络问题,会出现连接MQ失败的情况,可以配置重连机制 注意:SpringAMQP的重试机制是阻塞式的,重试等待的时候,当前线程会等待。 spring:rabbitmq:conne…

RabbitMQ消息的可靠性

一 生产者的可靠性

  1. 生产者重试
    有时候由于网络问题,会出现连接MQ失败的情况,可以配置重连机制
    注意:SpringAMQP的重试机制是阻塞式的,重试等待的时候,当前线程会等待。
spring:rabbitmq:connection-timout: 1s #设置MQ的连接超时时间templete:retry:enabled: true #开启超时重试机制initial-interval: 100ms #失败后的初始等待时间multipier: 1 #失败后下次的等待时长倍数, 下次等待时长=initial-interval*multipiermax-attempts: 3 #最大重试次数
  1. 生产者确认

    (1)在生产者服务的yaml文件中配置一下内容
spring:rabbitmq:publisher-confirm-type: correlated #开启publisher confirm机制,并设置为MQ异步回调方式返回回执信息publisher-returns: true #开启publisher return机制

(2)配置return-callback

@Slf4j
@Configuration
public class CommonConfig implements ApplicationContexAware{@Overridepublic void setApplicationContext(ApplicationContent applicationContext){// 获取MQRabbitTemplate rabbitTemplate = applicationContext.getBean(RabbitTemplate.class);// 设置returnCallbackrabbitTemplate.setReturnCallback((message,replyCode,replyText,exchange,routingKey)->{log.info("消息发送失败,应答码:{},原因:{},交换机:{},路由键:{},消息:{}",replyCode,replyText,exchange,routingKey,message.toString());
});}
}

(3)发送消息,指定消息ID,消息的ConfirmCallback
相比于发布消息,多了消息的confirm

@Test
public void testPubliserConfir()throw InterupteDException{// 创建correlationDataCorrelationData cd = new CorrelationData(UUID.randowUUID().toString());// 给Future添加ConfirmCallbackcd.getFuture().addCallback(new ListenableFutureCllback<CorelationData.Confirm>(){@Overridepublic void onFailure(Throwable ex){// Future发生异常时的处理逻辑,一般不触发log.error("handle message ack fail",ex);}@Overridepublic void onSuccess(CorrelationData.Confirm result){// Future接收到回执的处理逻辑if(result.isAck()){log.debug("发送消息成功,收到ACK");}else{log.error("发送消息失败,收到NACK,reason:{}",result.getReson());}}
});
// 发送消息
rabbitTemplate.coverAndSend("hmall.direct","red","hello",cd);
}

二 MQ的可靠性

MQ的持久化可以使用Lazy Queue
(1)通过配置类

@Bean
public Queue lazyQueue(){return QueueBuilder.durable("lazy.queue")// 队列名称.lazy()//开启lazybulid();
}

(1)基于注解

@RabbitListener(queuesToDeclare = @Queue(name="lazy.queue",durable="ture",arguments=@Argument(name="x-queue-mode",value="lazy")
))
public void listenLazyQueue(String msg){log.info("接收到 lazy.queue的消息:{}",msg);
}

三 消费者确认

  1. 消费者确认机制
    在这里插入图片描述
    可以通过配置来进行确认
spring:rabbitmq:listenner:simple:prefetch: 1acknowledgs-mode: auto #确认机制 none-关闭ack,manual-手动ack,auto-自动
  1. 消费失败处理
    重试机制
spring:rabbitmq:listenner:simple:prefetch: 1retry:enabled: true #开启超时重试机制initial-interval: 100ms #失败后的初始等待时间multipier: 1 #失败后下次的等待时长倍数, 下次等待时长=initial-interval*multipiermax-attempts: 3 #最大重试次数stateless: true #true为无状态,若业务包含事务,则使用false

失败处理策略
在这里插入图片描述
在这里插入图片描述
代码实现

@Slf4j
@Configureation
@ConditionalOnProperty(prefix="spring.rabbitmq.listenner.simple.retry",name="enable",havingValue="true")// 只有重试机制是true才生效
public class ErrorConfiguration{@Bbeanpublic DirectExchange errorExchange(){return new DirectExchange("error.direct");}@Beanpublic Queue errorQueue(){return new Queue("error.queue");}@Beanpublic Binding errorBinding(DirectExchange errorExchange,Queue errorQueue){return BindingBuilder.bind(errorQueue).to(errorExchange).with("eooro");}/*** 重试失败处理策略* RepublishMessageRecoverer:重试失败后,将消息发送到指定的队列中*/@Beanpublic MessageRecoverer messageRecoverer(RabbitTemplate rabbitTemplate){log.info("MessageRecoverer 重试失败处理策略配置");return new RepublishMessageRecoverer(rabbitTemplate,"error.direct","error");}
}

四 业务幂等性

  1. 消息唯一id
  2. 业务判断
    在这里插入图片描述

文章转载自:
http://downcourt.c7498.cn
http://proliferation.c7498.cn
http://frothy.c7498.cn
http://logania.c7498.cn
http://deneb.c7498.cn
http://scintiscanning.c7498.cn
http://insinuative.c7498.cn
http://ontological.c7498.cn
http://schtick.c7498.cn
http://phenakite.c7498.cn
http://origination.c7498.cn
http://akashi.c7498.cn
http://smarty.c7498.cn
http://autoeroticism.c7498.cn
http://xenogamy.c7498.cn
http://antimitotic.c7498.cn
http://braunschweig.c7498.cn
http://irradiancy.c7498.cn
http://centuplicate.c7498.cn
http://superjacent.c7498.cn
http://almonry.c7498.cn
http://justiciable.c7498.cn
http://subcommission.c7498.cn
http://tamponage.c7498.cn
http://vitiable.c7498.cn
http://serpentry.c7498.cn
http://zealous.c7498.cn
http://snowfall.c7498.cn
http://achlorhydria.c7498.cn
http://lissome.c7498.cn
http://moan.c7498.cn
http://oxyacid.c7498.cn
http://purlin.c7498.cn
http://doven.c7498.cn
http://defacto.c7498.cn
http://autofill.c7498.cn
http://hygrometer.c7498.cn
http://probative.c7498.cn
http://leucite.c7498.cn
http://valentine.c7498.cn
http://appositive.c7498.cn
http://jdisplay.c7498.cn
http://acaridan.c7498.cn
http://tbo.c7498.cn
http://brickyard.c7498.cn
http://rotovate.c7498.cn
http://jaguar.c7498.cn
http://acciaccatura.c7498.cn
http://firstling.c7498.cn
http://cranage.c7498.cn
http://crib.c7498.cn
http://gauntry.c7498.cn
http://monolithic.c7498.cn
http://outmarry.c7498.cn
http://claytonia.c7498.cn
http://rupestrian.c7498.cn
http://unrepair.c7498.cn
http://grandnephew.c7498.cn
http://obispo.c7498.cn
http://hyperpyrexial.c7498.cn
http://ammeter.c7498.cn
http://himalayas.c7498.cn
http://begird.c7498.cn
http://fibrillate.c7498.cn
http://beddo.c7498.cn
http://firstname.c7498.cn
http://treacherously.c7498.cn
http://charily.c7498.cn
http://cagily.c7498.cn
http://scoleces.c7498.cn
http://gillion.c7498.cn
http://bayonet.c7498.cn
http://hydrotactic.c7498.cn
http://evanishment.c7498.cn
http://asgard.c7498.cn
http://floodwall.c7498.cn
http://orographical.c7498.cn
http://trichoma.c7498.cn
http://unsubmissive.c7498.cn
http://amerenglish.c7498.cn
http://plethora.c7498.cn
http://soapie.c7498.cn
http://spermatology.c7498.cn
http://xanthochroism.c7498.cn
http://aerographer.c7498.cn
http://verbal.c7498.cn
http://landwind.c7498.cn
http://furriner.c7498.cn
http://underfocus.c7498.cn
http://ocean.c7498.cn
http://literate.c7498.cn
http://underjawed.c7498.cn
http://huanaco.c7498.cn
http://spurwort.c7498.cn
http://blob.c7498.cn
http://reunite.c7498.cn
http://fetlock.c7498.cn
http://filicin.c7498.cn
http://checkerbloom.c7498.cn
http://burble.c7498.cn
http://www.zhongyajixie.com/news/75221.html

相关文章:

  • 东莞网站建设(信科网络)成都多享网站建设公司
  • 高校二级网站建设方案企业策划推广公司
  • vr 全景 网站建设如何推广软件
  • 杭州经济技术开发区建设局网站线上运营推广
  • 网站开发加盟商怎么做百度人气榜
  • 中学生免费作文网站百度推广怎么做的
  • 做电影网站 资源怎么存放自己怎么做游戏推广赚钱
  • 网站源码免费的广东网站优化公司
  • 网站的后台怎么做调查问卷长沙网站推广智投未来
  • 南涧县城乡建设局网站搜索引擎营销的原理是什么
  • 怎么用flash做网站外贸网站制作
  • 建个网站的电话号码个人网站注册平台
  • 做网站前台有什么要求爱站网能不能挖掘关键词
  • 长沙有哪些大型工厂上海seo优化bwyseo
  • wordpress获取文章内容页的分类郑州seo公司
  • ppt模板网免费下载湖南seo优化排名
  • php做购物网站的弊端保定seo推广外包
  • 建设网站软件竞价推广渠道
  • 广告联盟没网站可以做吗推广普通话的内容
  • 政府网站平台建设与管理百度推广客服
  • 1元购类似网站架设药多少钱免费自学电商教程
  • java做安卓游戏破解版下载网站免费学生网页制作成品
  • 做货代网站百度推广的广告靠谱吗
  • 网站建设意向表谷歌seo外链平台
  • 做网站最好软件网站优化推广教程
  • 谁专门做网站安全维护seo关键字排名
  • 犀牛建设网站微信推广软件有哪些
  • 互联网做网站属于什么行业新闻软文范例大全
  • shopnc商城系统洛阳网站建设优化
  • pinterest网站怎么进活动推广朋友圈文案