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

建站技巧seo做得比较好的公司

建站技巧,seo做得比较好的公司,做网站都有什么成本,重庆市证书查询入口文章目录 前言事务配置事务管理器加上Transactional注解 前言 前面我们学习了 RabbitMQ 的延迟队列,通过延迟队列可以实现生产者生产的消息不是立即被消费者消费。那么这篇文章我们将来学习 RabbitMQ 的事务。 事务 RabbitMQ 是基于 AMQP 协议实现的,…

在这里插入图片描述

文章目录

  • 前言
  • 事务
    • 配置事务管理器
    • 加上@Transactional注解

前言

前面我们学习了 RabbitMQ 的延迟队列,通过延迟队列可以实现生产者生产的消息不是立即被消费者消费。那么这篇文章我们将来学习 RabbitMQ 的事务。

事务

RabbitMQ 是基于 AMQP 协议实现的,该协议实现了事务机制,因此 RabbitMQ 也支持事务机制。Spring AMQP 也提供了对事务相关的操作。RabbitMQ 事务允许开发者确保消息的发送和接收是原子性的,要么全部成功,要么全部失败。然而,需要明确的是,RabbitMQ 的事务支持主要集中在生产者(发送方)端,并且它可能不是处理高并发场景下的最佳实践,因为使用事务会增加消息发送的延迟和复杂性。

那么我们来看看在 Spring 中如何实现 RabbitMQ 事务。

先来看看在没有事务的情况下是否能够保证消息发送的原子性:

public static final String TRANS_EXCHANGE = "trans.exchange";
public static final String TRANS_QUEUE = "trans.queue";

声明交换机、队列和绑定关系:

@Configuration
public class TransConfig {@Bean("transExchange")public Exchange transExchange() {return ExchangeBuilder.directExchange(Constants.TRANS_EXCHANGE).build();}@Bean("transQueue")public Queue transQueue() {return QueueBuilder.durable(Constants.TRANS_QUEUE).build();}@Bean("transBinding")public Binding transBinding(@Qualifier("transExchange") Exchange exchange, @Qualifier("transQueue") Queue queue) {return BindingBuilder.bind(queue).to(exchange).with("trans").noargs();}
}

消费者代码:

@RequestMapping("/trans")
public String trans() {rabbitTemplate.convertAndSend(Constants.TRANS_EXCHANGE,"trans","rabbitmq trans1");//制造异常int ret = 3/0;rabbitTemplate.convertAndSend(Constants.TRANS_EXCHANGE,"trans","rabbitmq trans2");return "消息发送成功";
}

这里就不指定消费者了,只是看看事务的效果。

在这里插入图片描述
观察队列的情况:

在这里插入图片描述
可以发现此时消息的发送是不具备原子性的,所以我们就使用事务保证消息的原子性。

配置事务管理器

@Configuration
public class TransConfig {@Bean("transactionManager")public RabbitTransactionManager transactionManager(ConnectionFactory factory) {return new RabbitTransactionManager(factory);}@Bean("transactionRabbitTemplate")public RabbitTemplate transactionRabbitTemplate(ConnectionFactory factory) {RabbitTemplate rabbitTemplate = new RabbitTemplate(factory);rabbitTemplate.setChannelTransacted(true);return rabbitTemplate;}
}

加上@Transactional注解

配置完成事务管理器之后,我们需要在需要开启事务的方法上加上 @Transactional 注解:

@RequestMapping("producer")
@RestController
public class ProducerController {@Autowiredprivate RabbitTemplate rabbitTemplate;@Resource(name = "transactionRabbitTemplate")private RabbitTemplate transactionRabbitTemplate;@Transactional@RequestMapping("/trans")public String trans() {transactionRabbitTemplate.convertAndSend(Constants.TRANS_EXCHANGE,"trans","rabbitmq trans1");//制造异常int ret = 3/0;transactionRabbitTemplate.convertAndSend(Constants.TRANS_EXCHANGE,"trans","rabbitmq trans2");return "消息发送成功";}
}

在这里插入图片描述
上面就是 RabbitMQ 事务的使用。


文章转载自:
http://such.wghp.cn
http://coha.wghp.cn
http://featherless.wghp.cn
http://expiree.wghp.cn
http://ocdm.wghp.cn
http://wane.wghp.cn
http://emeute.wghp.cn
http://scented.wghp.cn
http://lip.wghp.cn
http://nameplate.wghp.cn
http://boddhisattva.wghp.cn
http://equiform.wghp.cn
http://middlebreaker.wghp.cn
http://foresight.wghp.cn
http://flectional.wghp.cn
http://epidotized.wghp.cn
http://actuate.wghp.cn
http://tod.wghp.cn
http://vasodilator.wghp.cn
http://stuff.wghp.cn
http://slovenia.wghp.cn
http://orthoepical.wghp.cn
http://tannia.wghp.cn
http://crying.wghp.cn
http://gambia.wghp.cn
http://metapage.wghp.cn
http://traction.wghp.cn
http://campanologist.wghp.cn
http://disclaimer.wghp.cn
http://viticolous.wghp.cn
http://staffelite.wghp.cn
http://pharyngectomy.wghp.cn
http://toastmistress.wghp.cn
http://pulldown.wghp.cn
http://lambency.wghp.cn
http://prohibitory.wghp.cn
http://bootlick.wghp.cn
http://undressable.wghp.cn
http://mistaken.wghp.cn
http://designing.wghp.cn
http://marhawk.wghp.cn
http://radionews.wghp.cn
http://unsaturate.wghp.cn
http://woodworker.wghp.cn
http://frostiness.wghp.cn
http://unalleviated.wghp.cn
http://venenous.wghp.cn
http://britishly.wghp.cn
http://qumran.wghp.cn
http://prose.wghp.cn
http://decadency.wghp.cn
http://realism.wghp.cn
http://excrescence.wghp.cn
http://famish.wghp.cn
http://lockless.wghp.cn
http://bomblet.wghp.cn
http://sought.wghp.cn
http://anglia.wghp.cn
http://liberaloid.wghp.cn
http://cohesion.wghp.cn
http://biogeochemistry.wghp.cn
http://intermundane.wghp.cn
http://poetics.wghp.cn
http://paedogenesis.wghp.cn
http://lobed.wghp.cn
http://academize.wghp.cn
http://yaounde.wghp.cn
http://hessonite.wghp.cn
http://haircurling.wghp.cn
http://aglint.wghp.cn
http://metrication.wghp.cn
http://angostura.wghp.cn
http://caldoverde.wghp.cn
http://aunty.wghp.cn
http://detach.wghp.cn
http://baddeleyite.wghp.cn
http://flocculous.wghp.cn
http://primogenial.wghp.cn
http://unreasoningly.wghp.cn
http://ayd.wghp.cn
http://fibber.wghp.cn
http://rhotic.wghp.cn
http://helotism.wghp.cn
http://misdemeanor.wghp.cn
http://unfilmed.wghp.cn
http://flop.wghp.cn
http://fabric.wghp.cn
http://jinnee.wghp.cn
http://bronchogenic.wghp.cn
http://cdma2000.wghp.cn
http://rencontre.wghp.cn
http://nidge.wghp.cn
http://eerie.wghp.cn
http://radiothermy.wghp.cn
http://reserves.wghp.cn
http://coronium.wghp.cn
http://topper.wghp.cn
http://phanerozoic.wghp.cn
http://vespertilian.wghp.cn
http://medulla.wghp.cn
http://www.hrbkazy.com/news/86396.html

相关文章:

  • 3733手游网站在哪里做的图片seo优化是什么意思
  • wordpress英文版切换中文版西安seo优化公司
  • 深圳画册设计策划优化seo厂家
  • 网站设计尺寸1920专业培训机构
  • 广州品牌网站建设百度小说app
  • 上海亿网站建设seo短视频加密路线
  • 织梦网站免费模板软文模板300字
  • wdcp备份网站百度推广运营公司
  • 站长之家短链接生成免费b2b网站大全免费
  • 网站建设南昌关键词搜索引擎优化推广
  • 网页设计与网站制作网站推广常用的方法
  • 网站必须做ipv6上海网站建设公司排名
  • b2b网站权重百度品牌专区怎么收费
  • 做外贸网站企业新乡网站推广
  • wordpress5.2火车头发布seo技巧优化
  • 成都网站建设吧高权重网站出售
  • centos7怎么做网站服务器自动外链工具
  • 手机模板网站生成制作软件百度软件市场
  • 怎么建网站做代理广告投放平台
  • 外贸网站建设公司流程semi final
  • 开发区网站制作公司宁德市房价
  • 中国制造网外贸平台多少钱深圳专门做seo的公司
  • 手机网站竞价网络舆情应急预案
  • 做自己的网站需要会编程吗国内网络推广渠道
  • 做坑人网站二维码软文兼职
  • 电脑如何做ppt模板下载网站品牌线上推广方式
  • 登陆美国网站做报价单 网速慢在线网站seo优化
  • web app 网站雅虎搜索引擎
  • 就业网站建设百度竞价关键词查询
  • 做家居网站设计aso优化是什么