- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 Spring Rabbit 消费者 A 和 B。
消费者A:
protected void process(Message amqpMessage, Channel channel)
throws Exception {
Session mysession=sessionRepository.findOne(5);
mysession.setMyField("bla");
sessionRepository.save(mysession);
ServicesHelper.convertAndSend(<Consumer B token>, mysession.getId());
}
消费者B:
protected void process(Message amqpMessage, Channel channel)
throws Exception {
//getting event from message
Long sessionId=5;
Session mysession=sessionRepository.findOne(sessionId);
mysession.setMyField("bla-bla");
//And I get there unpredictable optimistic locking exception.
sessionRepository.save(mysession);
}
看起来消费者 A 中的 jdbc 事务是在退出监听器方法后提交的,这就是可能发生重叠的原因。我的“ session ”条目有一个@Version 列,这就是我发现这个问题的原因。如何避免它?这是一个好方法吗?我只需要在消费者A中处理一个 session ,然后传递给消费者B即可。
最佳答案
我认为您可能在这里谈论 spring-data
而不是 spring-jdbc
。如果是这种情况(抱歉,如果不是)并且您正在使用 CrudRepository
,那么可能是因为与存储库的交互都是 @Transactional
。
例如,这里是 save 的实际签名
@Transactional
public <S extends T> S save(S entity) {
if (entityInformation.isNew(entity)) {
em.persist(entity);
return entity;
} else {
return em.merge(entity);
}
}
我建议重构以下内容并重试:-
protected void process(Message amqpMessage, Channel channel)
throws Exception {
ServicesHelper.convertAndSend(<Consumer B token>,adaptSession().getId()));
}
@Transactional
protected Session adaptSession(){
Session mysession=sessionRepository.findOne(5);
mysession.setMyField("bla");
sessionRepository.save(mysession);
return mysession;
}
和
@Transactional
protected void process(Message amqpMessage, Channel channel)
throws Exception {
//getting event from message
Long sessionId=5;
Session mysession=sessionRepository.findOne(sessionId);
mysession.setMyField("bla-bla");
//And I get there unpredictable optimistic locking exception.
sessionRepository.save(mysession);
}
这应该使交易单位匹配。尝试一下我就知道了。
关于java - Spring Rabbit 和 JDBC 事务问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40517987/
我必须用兔子、松鼠、狼和猎豹填充我的网格。我正在寻找字符串到类型对象的映射 populate("CHEETAH", 2); populate("WOLF", 3); populate("SQUIRRE
我们正在对业务异常进行重试操作,并使用 MessageRecoverer 进行几次尝试后存储消息,因此我们在 XML 中对重试进行了第一个配置,例如最大尝试次数和间隔等。在此链接中重试的属性 http
我目前正在研究 Rabbit-Mq,并试图实现一个“死信”队列,一个用于失败消息的队列。我一直在阅读兔子文档:https://www.rabbitmq.com/dlx.html . 并想出了这个例子:
我正在尝试使用 devstack 在 Ubuntu 12.04 上设置 OpenStack。现在,我得到的错误是: Setting up rabbitmq-server (2.7.1-0ubuntu4
我们有一个 RabbitMQ 交换器,它在我们系统的几个组件之间交换消息。 每个组件都是交易所的发布者和订阅者。 我们需要找到一种方法来确保每个应用程序都不会收到它发送到交换中的消息。 例如。 应用
我有一个不寻常的情况,如果我的应用程序在消息处理过程中已正常关闭(例如自动缩放),我不希望将带有重新传递标志的消息发送回队列。我希望仅在应用程序崩溃时才设置该标志。我的代码中有一个功能,可以以不同的方
我有 JRuby 代码: class Receiver def initialize(channel_id) @channel_id = channel_id factory =
Spring AMQP Reference说: Starting with version 1.3, the CachingConnectionFactory can be configured to
我以这种方式使用rabbitTemplate: localhost 发送至交易所: rabbitTemplate.setExch
从 this question 开始,我们有一个 Rabbit 凭证失效的场景,我们需要在我们的 CachingConnectionFactory 上调用 resetConnection() 来获取一
我有多个模块,它们通过消息队列 (Spring Rabbit) 相互通信。一些模块产生消息,而另一些模块使用它们。但是,单个模块可以监听不同的队列,我在列表中有一个队列名称列表,因此我为每个队列名称创
spring-rabbit 可以支持单个主题上的多个并发消费者吗? 详细信息如下 我的系统使用手动确认模式,通过 spring-rabbit (Spring 4.0.6) 进行主题交换。模式如下: 消
我想并行处理来自 rabbitMq 队列的消息。队列配置为 autoAck =false。我正在使用 camel-rabbitMQ 支持 camel endpoints ,它支持 threadPool
我正在开发一个支持 rabbitmq 的应用程序。所以,我有一个消费者和一个生产者。我需要在两种方式之间做出决定,如何在它们之间建立通信。 第一种方式 public void send(){ /
我有以下监听器方法: @Override public void onMessage(Message message, Channel channel) { try { // do som
如何在给其他消费者拒绝消息或一段时间后不回复后重复发送消息?不包括当前消费者? 最佳答案 对于 RabbitMQ,您可以使用 Acknowledgements .成功处理消息后,您的消费者将确认(确认
当我在交易所发布时收到 Nack 时,我在配置 ReturnCallback 时遇到问题。这是我所做的: CachingConnectionFactory connectionFactory = ne
我们使用 RabbitMQ 服务器在应用程序之间进行消息传递。我们需要为所有进入 Rabbit 服务器的 amqp 消息创建一个中央日志。我们的目的不是临时调试,而是可审计性。理想情况下,我可以先登录
RabbitMQ 似乎占用了太多磁盘空间并且无法启动。如何在我的 Mac 上删除它?我似乎找不到它。我已经尝试删除所有图像和容器,然后从头开始重建,希望它能解决问题。 $docker logs rab
我正在尝试进行rabbitmq http api调用,以了解队列的存在方式和其他信息... 我需要3个变量才能传递给api 1)网址:(http:// localhost:55672 / api)2)
我是一名优秀的程序员,十分优秀!