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; 
    } 
} 

[OK]を、ChannelSqsMessageDrivenChannelAdapterが定義されていますが、次は何していますか?私はそのような春の豆を持っているとしましょう:

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

@Component 
public class MyComponent { 
    public void onMessage(Message message) throws Exception { 
     //handle sqs message 
    } 
} 
  1. この コンポーネントにmyQueueからのすべてのメッセージを渡すためにどのようにtell春?
  2. でメッセージを処理する追加の設定はありますか?たとえば、メッセージSQSを受け取った後に処理を として処理し、他のクライアントには表示されないので、メッセージを1つだけ取り出すためには が必要です。 この現象は、デフォルトで有効になっていますか?

答えて

0

Spring Integration Reference Manualをお読みください。

@Component 
public class MyComponent { 

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

} 
1

あなたの2番目の質問に答える:デフォルトでは

/** 
* 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 processingSqsMessageDeletionPolicyオプションを使用して達成することができます質問:

/** 
* 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オブジェクトが必要なときにいつでもあなたのonMessage()メソッドから取得し、それを確認することができAwsHeaders.ACKNOWLEDGMENTメッセージヘッダ内に配置されています。

関連する問題