title: Amazon sns & sqs messages with java
body: <p>I have 2 different systems (A an B) that communicates using <a href="http://aws.amazon.com/sqs/" rel="noreferrer">amazon sqs</a>.
  System A sends messages to system B.</p>
  
  <p>Currently system B gets the messages using a separated thread that starts when the server goes up.
  Here is the run method:</p>
  
  <pre><code>@Override
  public void run() {
      while (true) {
          ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
          try {
              receiveMessageRequest.setWaitTimeSeconds(1);
              List&lt;Message&gt; messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
  
              for (Message message : messages) {
               // process messages
              }
          }
      }
  }
  </code></pre>
  
  <p>Looking at this code I have a feeling it is not efficient since it uses a busy waiting loop.
  I would expect to get the messages using some sort of push mechanism.</p>
  
  <p>Reading a bit about amazon <a href="http://aws.amazon.com/sqs/" rel="noreferrer">sqs</a> and <a href="http://aws.amazon.com/sns/" rel="noreferrer">sns</a> this seems possible using http (server B can expose servlets for that) but still I'm a bit confused. </p>
  
  <ul>
  <li>Which one (sns or sqs) should provide me this ability (pushing a message to server B)?</li>
  <li>What is the easiest way of doing it (any reference to code)?</li>
  </ul>