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()方法獲取並承認它,只要你需要。

相關問題