1

Herespring-integration-aws项目。它们提供例如关于入境Channle适配器:有人可以提供spring-integration-aws SQS用法的例子吗?

@SpringBootApplication 
public static class MyConfiguration { 

    @Autowired 
    private AmazonSQSAsync amazonSqs; 

    @Bean 
    public PollableChannel inputChannel() { 
     return new QueueChannel(); 
    } 

    @Bean 
    public MessageProducer sqsMessageDrivenChannelAdapter() { 
     SqsMessageDrivenChannelAdapter adapter = new SqsMessageDrivenChannelAdapter(this.amazonSqs, "myQueue"); 
     adapter.setOutputChannel(inputChannel()); 
     return adapter; 
    } 
} 

好吧,ChannelSqsMessageDrivenChannelAdapter的定义,但什么是下一个?让说,我有春豆这样的:

import com.amazonaws.services.sqs.model.Message; 

@Component 
public class MyComponent { 
    public void onMessage(Message message) throws Exception { 
     //handle sqs message 
    } 
} 
  1. 如何tell春天从myQueue所有消息传递给该 组件?
  2. 有没有其他的配置来处理邮件,其中一个是 ?例如,收到邮件SQS后,将它们标记为 处理,并且它们对其他客户端不可见,所以它是 只需要获取一条消息,处理nad接下来获取一条消息。 此行为是否默认启用?

回答

0

您应该阅读Spring Integration Reference Manual

@Component 
public class MyComponent { 

    @ServiceActivator(inputChannel = "inputChannel") 
    public void onMessage(Message message) throws Exception { 
     //handle sqs message 
    } 

} 
1

回答你的第二个问题:

/** 
* Configure the maximum number of messages that should be retrieved during one poll to the Amazon SQS system. This 
* number must be a positive, non-zero number that has a maximum number of 10. Values higher then 10 are currently 
* not supported by the queueing system. 
* 
* @param maxNumberOfMessages 
*  the maximum number of messages (between 1-10) 
*/ 
public void setMaxNumberOfMessages(Integer maxNumberOfMessages) { 
    this.maxNumberOfMessages = maxNumberOfMessages; 
} 

默认情况下它是10

问题有关mark them as processing可以与SqsMessageDeletionPolicy选项来实现:

/** 
* Never deletes message automatically. The receiving listener method must acknowledge each message manually by using 
* the acknowledgment parameter. 
* <p><b>IMPORTANT</b>: When using this policy the listener method must take care of the deletion of the messages. 
* If not, it will lead to an endless loop of messages (poison messages).</p> 
* 
* @see Acknowledgment 
*/ 
NEVER, 

这种Acknowledgment对象放入AwsHeaders.ACKNOWLEDGMENT消息头,你可以从你的onMessage()方法获取并承认它,只要你需要。

相关问题