Here是spring-integration-aws
项目。它们提供了有关Inbound Channle适配器的示例:
@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;
}
}
好的,Channel
和SqsMessageDrivenChannelAdapter
已定义,但下一步是什么?假设我有这样的春豆:
import com.amazonaws.services.sqs.model.Message;
@Component
public class MyComponent {
public void onMessage(Message message) throws Exception {
//handle sqs message
}
}
tell
将所有邮件从myQueue
传递给此邮件
分量θSQS
后将其标记为
处理并且它们对其他客户端不可见,所以它是
需要只获取一条消息,然后处理nad获取一条消息。是否
默认情况下启用此行为?答案 0 :(得分:1)
您应该阅读Spring Integration Reference Manual。
@Component
public class MyComponent {
@ServiceActivator(inputChannel = "inputChannel")
public void onMessage(Message message) throws Exception {
//handle sqs message
}
}
答案 1 :(得分: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()
方法获取该标题,并在需要时对其进行确认。