【发布时间】: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