我有一个使用jdbc:inbound-channel-adapter从DB读取数据的配置。配置:
<int-jdbc:inbound-channel-adapter query="SELECT * FROM requests WHERE processed_status = '' OR processed_status IS NULL LIMIT 5" channel="requestsJdbcChannel"
data-source="dataSource" update="UPDATE requests SET processed_status = 'INPROGRESS', date_processed = NOW() WHERE id IN (:id)" >
<int:poller fixed-rate="30000" />
</int-jdbc:inbound-channel-adapter>
<int:splitter input-channel="requestsJdbcChannel" output-channel="requestsQueueChannel"/>
<int:channel id="requestsQueueChannel">
<int:queue capacity="1000"/>
</int:channel>
<int:chain id="requestsChain" input-channel="requestsQueueChannel" output-channel="requestsApiChannel">
<int:poller max-messages-per-poll="1" fixed-rate="1000" />
.
.
</int:chain>在上面的配置中,我用30秒的fixed-rate定义了jdbc。当有直接通道而不是requestsQueueChannel时,select查询只获得5行(因为我使用的是限制select查询中的行),然后再等待30秒等待下一次轮询。
但是,在我介绍了带有队列的requestsQueueChannel并在requestsChain中添加了计票器之后,jdbc-inbound并不像预期的那样工作。下一次投票不会再等30秒。有时,它会在一行中轮询数据库两次(在一秒钟内),就好像有两个线程在运行一样,并从DB获得两组行。但是,除了上面提到的这些,没有异步切换。
我的理解是,即使存在requestsQueueChannel,一旦执行select查询,它也应该再等待30秒来轮询DB。我遗漏了什么吗?我只想了解这种配置的行为。
发布于 2015-01-07 09:29:52
Spring集成计票器激活两次(就好像它们是两个线程一样)的问题基本上与我在这里遇到的问题相同,即文件系统计票器:
How to prevent duplicate Spring Integration service activations when polling directory
显然,这是一个相对常见的错误配置,Spring和servlet上下文都加载Spring配置。因此,确实有两个线程,并且可以看到轮询器在其轮询期内激活了两次。通常在几秒钟内彼此之间,因为每个将启动时,其上下文加载。
我确保separation配置只在单个上下文中加载的方法是构造项目包以确保分离。
首先定义一个web配置,它只接收"web“包下的类。
@Configuration
@ComponentScan(basePackages = { "com.myapp.web" })
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}创建单独的根配置类来加载bean(例如服务和存储库),这些类不属于servlet上下文。其中一个应该加载Spring配置。即:
@Configuration
@ComponentScan(basePackages = { "com.myapp.eip" })
@ImportResource(value = { "classpath:META-INF/spring/integration-context.xml" })
public class EipConfig {
}配置中的另一个因素是,我的servlet过滤器和web安全配置需要在根上下文中而不是servlet上下文中。
发布于 2015-01-06 15:39:11
在使用DirectChannel时,直到当前轮询结束,才会考虑下一个轮询。
当使用QueueChannel (或任务执行器)时,轮询程序可以重新运行。
在默认情况下,入站适配器将max-messages-per-poll设置为1,因此您的配置应该按照预期工作。您能在某个地方张贴调试日志吗?
https://stackoverflow.com/questions/27801257
复制相似问题