Amazon sns & sqs messages with java

I have two different systems (A a B) that communicate using amazons sqs . System A sends messages to system B.

System B is currently receiving messages using a dedicated thread that starts when the server goes up. Here is the startup method:

@Override
public void run() {
    while (true) {
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
        try {
            receiveMessageRequest.setWaitTimeSeconds(1);
            List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

            for (Message message : messages) {
             // process messages
            }
        }
    }
}

Looking at this code, I feel that it is not efficient, as it uses a busy wait loop. I would expect messages to receive some kind of push mechanism.

Reading a bit about amazon sqs and sns this seems possible with http (server B can expose servlets for this), but still I'm a little confused.

  • Which one (sns or sqs) should provide me with this ability (pushing a message to server B)?
  • ( )?
+4
1

SNS B. SQS B .

/, . SNS, , A, B, .

, Amazon SQS B. B A . , B, , , (, ).

, , , , , , ( - ).

- . , ? SNS, . SQS - , . ?

SQS , ( 20 ) receiveMessage. , SQS, . , SNS, , SQS, . . http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html.

, AWS Java SDK, GitHub, AWS. . https://github.com/aws/aws-sdk-java/blob/master/src/samples/AmazonSimpleQueueService/SimpleQueueServiceSample.java http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.example.java.html SQS SNS .

SNS SQS. .. SNS SNS push- . . http://docs.aws.amazon.com/sns/latest/dg/SendMessageToSQS.html

+11

Source: https://habr.com/ru/post/1542429/


All Articles