这里是spring-integration-aws项目。它们提供了有关入站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 spring中的所有消息从myQueue传递到此组件?SQS将它们标记为处理,其他客户端看不到它们,因此只需要获取一条消息,然后处理nad获取一条消息。默认情况下启用此行为吗?发布于 2017-05-02 12:53:12
你应该读读弹簧集成参考手册。
@Component
public class MyComponent {
@ServiceActivator(inputChannel = "inputChannel")
public void onMessage(Message message) throws Exception {
//handle sqs message
}
} 发布于 2017-05-02 13:32:02
回答你的第二个问题:
/**
* 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()方法获得该消息头,并在需要时确认它。
https://stackoverflow.com/questions/43732681
复制相似问题