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

互联网销售公司seo是什么服务

互联网销售公司,seo是什么服务,电子商务网站建设期末试题答案05,东莞市寮步镇防疫新闻最新问题描述 在一个事务内完成插入操作,通过MQ异步通知其他微服务进行事件处理。 由于是在事务内发送,其他服务消费消息,查询数据时还不存在如何解决呢? 解决方案 通过spring-tx包的TransactionSynchronizationManager事务管理器解…

问题描述

在一个事务内完成插入操作,通过MQ异步通知其他微服务进行事件处理。
由于是在事务内发送,其他服务消费消息,查询数据时还不存在如何解决呢?


解决方案

通过spring-tx包的TransactionSynchronizationManager事务管理器解决。

public abstract class TransactionSynchronizationManager {private static final ThreadLocal<Set<TransactionSynchronization>> synchronizations =new NamedThreadLocal<>("Transaction synchronizations");/*** Return if transaction synchronization is active for the current thread.* Can be called before register to avoid unnecessary instance creation.* @see #registerSynchronization*/		public static boolean isSynchronizationActive() {return (synchronizations.get() != null);}/*** Register a new transaction synchronization for the current thread.* Typically called by resource management code.* <p>Note that synchronizations can implement the* {@link org.springframework.core.Ordered} interface.* They will be executed in an order according to their order value (if any).* @param synchronization the synchronization object to register* @throws IllegalStateException if transaction synchronization is not active* @see org.springframework.core.Ordered*/public static void registerSynchronization(TransactionSynchronization synchronization)throws IllegalStateException {Assert.notNull(synchronization, "TransactionSynchronization must not be null");Set<TransactionSynchronization> synchs = synchronizations.get();if (synchs == null) {throw new IllegalStateException("Transaction synchronization is not active");}synchs.add(synchronization);}}

Rocketmq方法封装,通过TransactionSynchronizationManager.isSynchronizationActive()判断当前方法的调用是否在事务内。
如果是,则注册一个事务同步适配器,在事务提交后发送消息。
否则直接发送。

    /*** 事务内发送 mq时使用,强制到事务结束后发送*/public SendResult sendAfterTrans(String topic, String tag, String key, String body) {final SendResult[] res = new SendResult[1];try {// 是否开启事务判断if (TransactionSynchronizationManager.isSynchronizationActive()) {log.debug("Mysql事务内Mq消息发送  延迟到事务提交后 waiting……");TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {@Overridepublic void afterCommit() {log.debug("Mysql事务内Mq消息发送  发送消息 body:{}", body);res[0] = send(topic, tag, key, body);}});} else {return this.send(topic, tag, key, body);}} catch (Exception e) {e.printStackTrace();}return res[0];}

在这里插入图片描述

http://www.mnyf.cn/news/53017.html

相关文章:

  • jquery 苹果网站做网络推广好吗
  • 做的好的手机网站有哪些百度竞价渠道代理
  • 做司法考试题目的网站软文发布公司
  • 中石化网站群建设福州seo结算
  • 怎样做百度网站推广营销型网站定制
  • 免费发布信息网站有哪些网络运营推广合作
  • 北京商场面积排名广东网站se0优化公司
  • 公司网站建设企业关键词搜索点击软件
  • wordpress 子目录建站产品软文范例软文
  • 正规购物网站建设网站优化外包多少钱
  • 网站ico在后台哪里找到境外电商有哪些平台
  • 专做网站漏扫的工具网络营销的含义是什么
  • 微信文章采集 wordpressseo网站有优化培训吗
  • 建设银行人力资源系统网站怎么进推广平台排行榜有哪些
  • 遂宁市住房与城乡建设厅网站如何提升网站搜索排名
  • 网站建设遵循的原则是什么网络营销策划
  • 做网站什么时候要用到虚拟主机百度搜索优化建议
  • 建设网站需要注意什么成人用品哪里进货好
  • 提高网站收录三亚网络推广
  • 网站设计网站开发ps培训
  • 外网访问不了内网建设的网站长尾关键词挖掘网站
  • 重庆建站塔山双喜百度指数分析案例
  • php零基础做网站线上宣传方式
  • 海尔建设此网站的目的杭州seo公司哪家好
  • wordpress最佳固定链接seo实战优化
  • 涉密项目单位网站建设流程查询网址域名
  • 多配色创意metro风格企业网站织梦模板整四川旅游seo整站优化站优化
  • 网站授权合同刷推广链接的网站
  • 免费建电子商务网站上海百度整站优化服务
  • 怎么把个人做的网站上传到网上抖音搜索seo代理