到目前为止,我已经实现了 Spring XD 处理器,例如像这样:
@MessageEndpoint
public class MyTransformer
{
@Transformer( inputChannel = "input", outputChannel = "output" )
public String transform( String payload )
{
...
}
};
但是,我现在坚持实施自定义接收器。当前的文档不是很有帮助,因为它只是通过 XML“神奇地”配置了一些东西:
<beans ...>
<int:channel id="input" />
<int-redis:store-outbound-channel-adapter
id="redisListAdapter" collection-type="LIST" channel="input" key="${collection}" auto-startup="false"/>
<beans:bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<beans:property name="hostName" value="${host}" />
<beans:property name="port" value="${port}" />
</beans:bean>
</beans>
这将使用 redis store-outbound-channel-adapter 作为接收器。但是,文档并没有告诉我如何创建一个简单的通用接收器,该接收器仅具有一个输入通道并使用一条消息。
那么有人可以为我提供一个最小的工作示例吗?
接收器就像处理器一样,但没有输出通道;用一个@ServiceActivator
调用您的代码(应该有一个void
返回)。
@MessageEndpoint
public class MyService
{
@ServiceActivator( inputChannel = "input")
public void handle( String payload )
{
...
}
};
EDIT
对于来源,有两种类型:
轮询(从源拉取消息):
@InboundChannelAdapter(value = "output",
poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public String next() {
return "foo";
}
消息驱动(源推送消息):
@Bean
public MySource source() {
// return my subclass of MessageProducer that has outputChannel injected
// and calls sendMessage
// or use a simple POJO that uses MessagingTemplate.convertAndSend(foo)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)