i use spring integeration redis,poll message from redis, like this:
@Bean
public PseudoTransactionManager transactionManager() {
final PseudoTransactionManager pseudoTransactionManager = new PseudoTransactionManager();
return pseudoTransactionManager;
}
@Bean
public TransactionSynchronizationFactory transactionSynchronizationFactory() {
ExpressionEvaluatingTransactionSynchronizationProcessor transactionSynchronizationProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
transactionSynchronizationProcessor.setAfterCommitExpression(this.PARSER.parseExpression("#store.rename('commit')"));
transactionSynchronizationProcessor.setAfterRollbackExpression(this.PARSER.parseExpression("#store.rename('roll')"));
DefaultTransactionSynchronizationFactory transactionSynchronizationFactory = new DefaultTransactionSynchronizationFactory(transactionSynchronizationProcessor);
return transactionSynchronizationFactory;
}
@Bean
public SourcePollingChannelAdapterFactoryBean sourcePollingChannelAdapter(RedisStoreMessageSource redisStoreMessageSource, TransactionSynchronizationFactory transactionSynchronizationFactory) {
SourcePollingChannelAdapterFactoryBean sourcePollingChannelAdapterFactoryBean = new SourcePollingChannelAdapterFactoryBean();
sourcePollingChannelAdapterFactoryBean.setAutoStartup(true);
sourcePollingChannelAdapterFactoryBean.setOutputChannelName("mail-delivery-status-route-channel");
sourcePollingChannelAdapterFactoryBean.setSource(redisStoreMessageSource);
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setMaxMessagesPerPoll(10);
pollerMetadata.setTransactionSynchronizationFactory(transactionSynchronizationFactory);
PeriodicTrigger periodicTrigger = new PeriodicTrigger(2000);
pollerMetadata.setTrigger(periodicTrigger);
sourcePollingChannelAdapterFactoryBean.setPollerMetadata(pollerMetadata);
return sourcePollingChannelAdapterFactoryBean;
}
@Bean
public TestHandler testHandler() {
return new TestHandler();
}
@Bean
public IntegrationFlow trans() {
return flow -> flow.channel("mail-delivery-status-route-channel").handle(testHandler());
}
Normally, after the process is complete, the afterCommit #store.rename('commit')
operation will be performed, but it is not doing it now, and will continue polling , i debug ,find that: AbstractPollingEndpoint#bindResourceHolderIfNecessary
TransactionSynchronizationManager.isActualTransactionActive()
is always false.
How can I improve the program.