【问题标题】:Spring poller roll back on exception after a particular retry countSpring poller 在特定重试计数后回滚异常
【发布时间】:2015-11-25 15:12:20
【问题描述】:

我的轮询器从数据库中获取数据并将其传递给服务激活器。 如果服务激活器方法中发生任何异常,我应该将获取的数据回滚到之前的状态,并且应该再次将相同的数据发送到服务激活器,仅针对特定的重试计数(比如 3)。 **是否可以在 xml 配置中执行此操作。 ?有关详细信息,我将分享轮询器配置和服务激活器。 poller.xml

	<int-jdbc:inbound-channel-adapter id="datachannel"
		query="select loyalty_id,process_id,mobile_uid from TBL_RECEIPT where r_cre_time
		=(select min(r_cre_time) from TBL_RECEIPT where receipt_status=0)"
		data-source="dataSource" max-rows-per-poll="1"
		update="update TBL_RECEIPT set receipt_status=11 where process_id in (:process_id)">
		<int:poller fixed-rate="5000">
		<int:transactional/>
		</int:poller>
	</int-jdbc:inbound-channel-adapter>


<int:channel id="errors">
<int:queue/>
</int:channel>

   <bean id="poller" class="main.java.com.as.poller.PollerService" />

	<int:channel id="executerchannel">
		<int:dispatcher task-executor="taskExecutor" />
	</int:channel> 


	<task:executor id="taskExecutor" pool-size="2" />

	<int:service-activator input-channel="datachannel"
		output-channel="executerchannel" ref="poller" method="getRecordFromPoller">
			<int:request-handler-advice-chain>
		<int:retry-advice recovery-channel="errors" />
		</int:request-handler-advice-chain>
	</int:service-activator>
	

     <int:service-activator input-channel="executerchannel"
		ref="poller" method="getDataFromExecuterChannel">
	</int:service-activator>
	

服务激活方法

@SuppressWarnings({ "unchecked", "rawtypes" })

	@ServiceActivator

	public void processMessage(Message message) throws IOException {
		int capLimit = Integer.parseInt(env.getProperty("capping_limit"));
		
		List<Map<String, Object>> rows = (List<Map<String, Object>>) message
				.getPayload();
		for (Map<String, Object> row : rows) {
			String loyaltyId = (String) row.get("loyalty_id");
			String processId = (String) row.get("process_id");
			String xid=(String)row.get("mobile_uid");

我听说 int:transactional 在轮询器配置中被使用。但是当我添加它时,即使在成功事务后它也会记录相同的记录。(意味着它每次都会回滚)。 谁能帮我解决这个问题?

【问题讨论】:

  • 我能问一下你为什么要执行相同的东西,知道它会失败吗?
  • 来自服务激活器,我正在调用外部系统。如果我从该服务中得到任何异常,我需要回滚事务并重试

标签: spring spring-integration rollback


【解决方案1】:

您可以将retry request-handler-advice 添加到服务激活器。

要使重试有状态(抛出异常以便事务回滚),您需要提供RetryStateGenerator。否则,线程将在重试期间被挂起。

无论使用有状态或无状态重试,您确实应该使用事务轮询器,以便仅在成功后应用更新。

表示每次都回滚

事务轮询器只会在抛出异常时回滚。因此,如果您看到同一行,则一定是有问题。

为所有org.springframework 启用调试日志记录以跟踪消息流和事务活动。

【讨论】:

  • 我会试试这个,让你知道。感谢您的宝贵时间
  • 从您提供的链接docs.spring.io/spring-integration/reference/html/… ... 重试建议 (o.s.i.handler.advice.RequestHandlerRetryAdvice) 利用了丰富的重试机制。我找不到这个 class.jetty 服务器正在抛出错误.我知道我问这个很愚蠢,但我不知道。我应该在自己身上创建一个名为 RequestHandlerRetryAdvice 的类吗?如果是的话,我应该在那个类中写什么?你能澄清一下吗?
  • o.s.i. 是缩写 - 请参阅 here。该类在spring-integration-core,在2.2版本中引入;当前版本是 4.2.2。
  • 所以我应该用真实姓名替换o.s.i?我使用的是spring版本4.1.6
  • 是的;如果您使用 IDE(例如 IDEA 或 eclipse/STS),您应该能够只输入 Simple 类名,IDE 将自动填充其余部分。
猜你喜欢
  • 2018-01-17
  • 1970-01-01
  • 2015-02-12
  • 2018-08-09
  • 2022-07-22
  • 2019-06-30
  • 1970-01-01
  • 1970-01-01
  • 2016-11-03
相关资源
最近更新 更多