本文介绍了如何实现Spring XD接收器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经实现了Spring XD处理器,例如:像这样:

So far I have implemented Spring XD processors, e.g. like this:

@MessageEndpoint
public class MyTransformer 
{

   @Transformer( inputChannel = "input", outputChannel = "output" )
   public String transform( String payload )
   {
      ...
   }
};

但是,我现在坚持实施自定义接收器。当前的文档不是很有用,因为它只是通过XML神奇地配置一些东西:

However, I am stuck at implementing a custom sink now. The current documentation is not very helpful, since it simply configures something "magically" via 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作为接收器。但是,文档并没有告诉我如何创建一个简单的通用接收器,它只有一个输入通道并消耗一条消息。

This will use the redis store-outbound-channel-adapter as a sink. However, the documentation does not tell me how to create a simple, generic sink that simply has one input channel and consumes a message.

那么有人能为我提供一个最小的工作示例吗?

So can anyone provide me with a minimal working example?

推荐答案

接收器就像处理器但没有输出通道;使用 @ServiceActivator 来调用你的代码(应该有 void 返回)。

A sink is just like a processor but without an output channel; use a @ServiceActivator to invoke your code (which should have a void return).

@MessageEndpoint
public class MyService  
{

    @ServiceActivator( inputChannel = "input")
    public void handle( String payload )
    {
        ...
    }

};

编辑

对于消息来源,有两种类型:

For sources, there are two types:

轮询(消息来自消息来源):

Polled (messages are pulled from the source):

@InboundChannelAdapter(value = "output", 
        poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public String next() {
    return "foo";
}

消息驱动(源推送消息的地方):

Message-driven (where the source pushes messages):

@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)
}

这篇关于如何实现Spring XD接收器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 01:14