spring - 如果未连接外部服务,如何使用 `ReceiveMessageAdvice` 添加智能“轮询”以防止轮询
问题描述
我当前的工作 XML 配置如下所示:
生产者 -> 网关 -> 队列通道(保留在 Oracle DB 上) -> 接收者服务 -> 具有外部会话的服务(例如 TCP/IP)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="outboundFixMessageService" class="com.myapp.OutboundFixMessageService"/>
<int:gateway service-interface="com.myapp.queue.DpOutgoingMessageGateway"
default-request-channel="outgoingChannel"></int:gateway>
<int:channel id="outgoingChannel">
<int:queue message-store="outgoingMessageChannelStore"/>
</int:channel>
<int:service-activator ref="outboundFixMessageService"
method="processOutgoingMessageString"
input-channel="outgoingChannel">
<int:poller fixed-rate="10" time-unit="SECONDS" max-messages-per-poll="1000">
<int:transactional propagation="NESTED" />
</int:poller>
</int:service-activator>
<!-- Persisting queue -->
<bean id="outgoingMessageChannelStore" class="org.springframework.integration.jdbc.store.JdbcChannelMessageStore">
<property name="dataSource" ref="dataSource"/>
<property name="channelMessageStoreQueryProvider" ref="jdbcChannelMessageStoreQueryProvider"/>
<property name="region" value="TX_TIMEOUT"/>
</bean>
<bean id="jdbcChannelMessageStoreQueryProvider" class="org.springframework.integration.jdbc.store.channel.H2ChannelMessageStoreQueryProvider" />
<int:transaction-synchronization-factory id="jdbcChannelMessageStoreFactory">
<int:after-commit expression="@jdbcChannelMessageStore.removeFromIdCache(headers.id.toString())" />
<int:after-rollback expression="@jdbcChannelMessageStore.removeFromIdCache(headers.id.toString())" />
</int:transaction-synchronization-factory>
</beans>
现在,如果服务激活器没有与外部连接的活动会话,我想添加智能“轮询”以ReceiveMessageAdvice
防止轮询。outboundFixMessageService
但是我不知道如何配置它,我又找不到在哪里查找示例项目。
如果您能提出一些建议,那就太好了。
提前致谢
解决方案
ReceiveMessageAdvice
为您的目的覆盖的has 方法:
/**
* Subclasses can decide whether to {@link MethodInvocation#proceed()} or not.
* @param source the source of the message to receive.
* @return true to proceed (default).
*/
default boolean beforeReceive(Object source) {
return true;
}
因此,如果您有一个钩子来检查该会话的状态,您只需false
从该方法返回并且不会发生轮询。
推荐阅读
- java - 通用输入不会存储在类变量中
- c - Linux C程序:如何找到函数所属的库
- php - 无法使用变量字符串获取表名 MYSQL 错误
- php - 为什么代码不能正常工作(解析器 phpQuery)?
- python - 给定范围Python中的素数
- javascript - 根据 Vuetify 下拉菜单中选择的内容动态填充表格
- java - 访问 WEB-INF 文件夹中子文件夹中的 JSP?
- node.js - Node.js MongoDb 查找函数忽略等待
- image - 如何从字节数组动态放置图像位置水晶报表
- centos - elrepo 存档元数据未列出截至 2018 年 10 月 1 日 0600 UTC 的 kernel-lt