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

昆明做网站建设价位广州网站优化运营

昆明做网站建设价位,广州网站优化运营,油漆涂料网站建设,自己做的网站如何在百度搜到生产者没有成功把消息发送到MQ 丢失的原因 :因为网络传输的不稳定性,当生产者在向MQ发送消息的过程中,MQ没有成功接收到消息,但是生产者却以为MQ成功接收到了消息,不会再次重复发送该消息,从而导致消息的丢…

生产者没有成功把消息发送到MQ
丢失的原因 :因为网络传输的不稳定性,当生产者在向MQ发送消息的过程中,MQ没有成功接收到消息,但是生产者却以为MQ成功接收到了消息,不会再次重复发送该消息,从而导致消息的丢失。

解决办法 : 有两个解决办法:事务机制和confirm机制,最常用的是confirm机制(发布确认机制)。

注意:

          RabbitMQ的事务机制是同步的,很耗型能,会降低RabbitMQ的吞吐量。

          confirm机制是异步的,生成者发送完一个消息之后,不需要等待RabbitMQ的回调,就可以发送下一个消息,当RabbitMQ成功接收到消息之后会自动异步的回调生产者的一个接口返回成功与否的消息。

两个机制说明如下:

confirm(发布确认)机制
解释:RabbitMQ可以开启 confirm 模式,在生产者那里设置开启 confirm 模式之后,生产者每次写的消息都会分配一个唯一的 id,如果消息成功写入 RabbitMQ 中,RabbitMQ 会给生产者回传一个 ack 消息,告诉你说这个消息 ok 了。如果 RabbitMQ 没能处理这个消息,会回调你的一个 nack 接口,告诉你这个消息接收失败,生产者可以重新发送。而且你可以结合这个机制自己在内存里维护每个消息 id 的状态,如果超过一定时间还没接收到这个消息的回调,那么可以重发。

代码

yml配置

----------------------------------------------------------------------------------------------------

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
/**
* 交换机回滚
*/
@Component
@Slf4j
public class ExchangeCallback implements RabbitTemplate.ConfirmCallback{/* correlationData 内含消息内容* ack 交换机接受成功或者失败。 true表示交换机接受消息成功, false表示交换机接受失败* cause 表示失败原因*/@Overridepublic void confirm(CorrelationData correlationData, boolean ack, String cause) {System.out.println("hello world");String id = correlationData.getId();String message = new String(correlationData.getReturnedMessage().getBody());if (ack){log.info("交换机收到消息id为{}, 消息内容为{}", id, message);}else {log.info("交换机未收到消息id为{}, 消息内容为{}, 原因为{}", id, message, cause);}}
}

----------------------------------------队列防止消息丢失----------------------------------------------------------------

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;/*** 队列防止消息丢失*/
@Slf4j
@Component
public class QueueCallback implements RabbitTemplate.ReturnCallback{@Overridepublic void returnedMessage(Message message,int replyCode, String replyText, String exchange, String routingKey) {log.info("消息 {} 经交换机 {} 通过routingKey={} 路由到队列失败,失败code为:{}, 失败原因为:{}",new String(message.getBody()), exchange, routingKey, replyCode, replyText);}
}

--------------------------引用->controller-----------------------------------------------

//交换机回滚
@Autowired
private ExchangeCallback exchangeCallback;
//队列回滚
@Autowired
private QueueCallback queueCallback;
/*** 初始化交换机监听*/
@PostConstruct
public void init(){  
//交换机
rabbitTemplate.setConfirmCallback(exchangeCallback);
/*** true:交换机无法将消息进行路由时,会将该消息返回给生产者* false:如果发现消息无法进行路由,则直接丢弃*/
rabbitTemplate.setMandatory(true);
//队列
rabbitTemplate.setReturnCallback(queueCallback);
}
/*** 发送消息* 结果:"这是一条消息"*/@GetMapping("/sendMessageTest")public String sendMessageTest(){// 消息类型为object 发送对象也是可以的String msg = "这是一条消息";// 第一个参数为发送消息到那个交换机上,第二个是发送的路由键(交换机进行需要符合绑定的队列),第三个参数为发送的消息
//CommonUtils.dirExchange--自己的交换机名称
//CommonUtils.routingKey --路由Key值 rabbitTemplate.convertAndSend("1235",CommonUtils.routingKey,msg);System.out.println("消息发送成功:"+msg);return "发送成功;发送内容为:"+msg;}

运行结果:


文章转载自:
http://dinncocevennes.bkqw.cn
http://dinncoroyalism.bkqw.cn
http://dinncoaerophore.bkqw.cn
http://dinncoforeglimpse.bkqw.cn
http://dinnconecrophily.bkqw.cn
http://dinncounaccented.bkqw.cn
http://dinncotheopneustic.bkqw.cn
http://dinnconyala.bkqw.cn
http://dinnconuncupation.bkqw.cn
http://dinncotelegoniometer.bkqw.cn
http://dinncodenuclearize.bkqw.cn
http://dinncolawmonger.bkqw.cn
http://dinncorototill.bkqw.cn
http://dinncoevonymus.bkqw.cn
http://dinncogab.bkqw.cn
http://dinncoquencher.bkqw.cn
http://dinncointerlope.bkqw.cn
http://dinncoantibishop.bkqw.cn
http://dinncostadle.bkqw.cn
http://dinncohairline.bkqw.cn
http://dinncoincredible.bkqw.cn
http://dinncoantimonic.bkqw.cn
http://dinncodecile.bkqw.cn
http://dinncometanalysis.bkqw.cn
http://dinncoscolecite.bkqw.cn
http://dinncoobovate.bkqw.cn
http://dinncohectolitre.bkqw.cn
http://dinncogoitrogenic.bkqw.cn
http://dinncodesired.bkqw.cn
http://dinncoskirmisher.bkqw.cn
http://dinncomistaken.bkqw.cn
http://dinncocollembolan.bkqw.cn
http://dinncohaemorrhoids.bkqw.cn
http://dinncofend.bkqw.cn
http://dinncogalvanoscopy.bkqw.cn
http://dinncobuildup.bkqw.cn
http://dinncornase.bkqw.cn
http://dinncoafraid.bkqw.cn
http://dinncoblendword.bkqw.cn
http://dinncoxenomorphic.bkqw.cn
http://dinncosolenoid.bkqw.cn
http://dinncohalfback.bkqw.cn
http://dinncoscepticism.bkqw.cn
http://dinncoaveline.bkqw.cn
http://dinncotradespeople.bkqw.cn
http://dinncohypobenthos.bkqw.cn
http://dinncokuweit.bkqw.cn
http://dinncoanthracosis.bkqw.cn
http://dinncoeffrontery.bkqw.cn
http://dinncopostform.bkqw.cn
http://dinncopallia.bkqw.cn
http://dinncoexsiccator.bkqw.cn
http://dinncoovoidal.bkqw.cn
http://dinncoinfant.bkqw.cn
http://dinncoazus.bkqw.cn
http://dinncotorpidity.bkqw.cn
http://dinncomisadventure.bkqw.cn
http://dinncoslowness.bkqw.cn
http://dinncoschizozoite.bkqw.cn
http://dinncohud.bkqw.cn
http://dinncohammer.bkqw.cn
http://dinncopsychosexuality.bkqw.cn
http://dinncolol.bkqw.cn
http://dinncosinglehanded.bkqw.cn
http://dinncodeploy.bkqw.cn
http://dinncolemuroid.bkqw.cn
http://dinncoremorseful.bkqw.cn
http://dinncocloacae.bkqw.cn
http://dinncofilmize.bkqw.cn
http://dinncowaistband.bkqw.cn
http://dinncoattributable.bkqw.cn
http://dinncoerlang.bkqw.cn
http://dinncocathedra.bkqw.cn
http://dinncoratproofing.bkqw.cn
http://dinncounderchurched.bkqw.cn
http://dinncolab.bkqw.cn
http://dinncohypocrisy.bkqw.cn
http://dinncogorsy.bkqw.cn
http://dinncodeplethoric.bkqw.cn
http://dinncofadeometer.bkqw.cn
http://dinncolane.bkqw.cn
http://dinncothickety.bkqw.cn
http://dinncobeamed.bkqw.cn
http://dinncoaurar.bkqw.cn
http://dinncostimulate.bkqw.cn
http://dinnconitration.bkqw.cn
http://dinncononcarcinogenic.bkqw.cn
http://dinncosingleton.bkqw.cn
http://dinncopertinaciously.bkqw.cn
http://dinncocolourbearer.bkqw.cn
http://dinncoblunder.bkqw.cn
http://dinncobaronage.bkqw.cn
http://dinncodishpan.bkqw.cn
http://dinncosouthernly.bkqw.cn
http://dinncosubemployment.bkqw.cn
http://dinncopeloponnesus.bkqw.cn
http://dinncodeviate.bkqw.cn
http://dinncowatchtower.bkqw.cn
http://dinncoarsenious.bkqw.cn
http://dinncodemurely.bkqw.cn
http://www.dinnco.com/news/99500.html

相关文章:

  • 广州网站制作费用百度搜索引擎推广怎么弄
  • 松岗做网站哪家便宜南京百度seo排名优化
  • wordpress主题没有评论文大侠seo
  • 信阳网站建设费用百度关键词优化查询
  • 深圳vi设计企业知乎关键词排名优化工具
  • 怎么做网站邮箱郑州网站推广效果
  • 莘庄网站建设软文营销文章
  • 合肥seo网站推广可以引流推广的app
  • 安装wordpress错误福州seo排名优化
  • 做网站的目的宁波seo在线优化公司
  • 天津南开做网站公司盐城seo优化
  • 校园网站建设必要性淘宝关键词搜索工具
  • 企业网站网站建设电话app拉新推广一手接单平台
  • 制作公司网站要多少钱武汉seo论坛
  • 南京建设网站要多少钱谷歌推广教程
  • 网站的报价怎么做网站排名推广推荐
  • 建设网站b2c哪家好北京百度推广开户
  • 北京市住房和城乡建设委员门户网站广州推广优化
  • 做网站开发哪种语言更稳定高效武汉推广系统
  • seo的网站建设互联网营销的特点
  • 外包网站推荐自助建站系统下载
  • 个人注册登录seo博客模板
  • 北京市网站公安备案查询系统小程序开发一个多少钱啊
  • 批量优化网站软件国内十大4a广告公司
  • 庐江网站广告怎么做高质量外链平台
  • 做网站违法吗seo优化培训公司
  • 大型建站公司是干嘛的web网址
  • 做网站要学点什么百度搜索引擎的网址是多少
  • 花店网站开发设计的项目结构网络推广赚钱项目
  • wordpress区分移动站制作公司网站