通道适配器和服务激活器

时间:2015-07-06 17:05:22

标签: spring spring-integration amazon-sqs

我是Spring框架和Spring Integration的新手。我开始使用AWS服务进行spring boot。我尝试使用通道适配器和服务激活器从SQS队列获取消息,并使用轮询器定期发送到应用程序内的另一个服务。

@configuration
public class AppConfig 
{

  @Bean
  @InboundChannelAdapter( value = "inputChannel", poller = @Poller(fixedDelay = "1000"))
  public Message inboundAdaptor ()
  {
   //get message from SQS queue
   System.out.println("get message");
   return message;
  }

  @Bean
  @ServiceActivator(inputChannel = "inputChannel")
  public String msgActivator( Message message)
  {
   //call another service and pass message body to that service
   System.out.println("This is message body" + messageBody);
   return messageBody;
  }

我希望通过上面的操作,InboundChannelAdaptor内的操作会定期调用,因为poller会自动使用ServiceActivator将消息信息传递给我的服务,只要我在{{{ 1}}。

我用SQS queue对它们进行了测试,以显示我所拥有的内容。但是,System.out.println( )仅为每种方法打印一次。这是否意味着poller仅轮询一次并停止或我无法使用System.out.println( )测试定期通话?

对于实施此工作流程的正确方法的任何建议表示赞赏。

1 个答案:

答案 0 :(得分:1)

@InboundChannelAdapter上使用@Bean时,bean必须是MessageSource类型。同样,对于bean上的@ServiceActivator,它必须是MessageHandler

对于像你这样的POJO方法,带注释的方法必须是@Bean ...

中的方法
@Bean
public MyBean myBean() {
    return new MyBean();
}

@MessageEndpoint
public static class MyBean {

    @InboundChannelAdapter( value = "inputChannel", poller = @Poller(fixedDelay = "1000"))
    public Message inboundAdaptor () {
        //get message from SQS queue
        System.out.println("get message");
        return message;
    }

    @ServiceActivator(inputChannel = "inputChannel", outputChannel="out")
    public String msgActivator( Message message) {
        //call another service and pass message body to that service
        System.out.println("This is message body" + messageBody);
        return messageBody;
    }

}

从服务返回回复时,您还需要输出通道。

相关问题