title: Slow message consumption using AmazonSQSClient
body: <p>So, i used concurrency in spring jms 50-100, allowing max connections upto 200. Everything is working as expected but if i try to retrieve 100k messages from queue, i mean there are 100k messages on my sqs and i reading them through the spring jms normal approach.</p>
  
  <pre><code>@JmsListener
  Public void process (String message) {
  count++;
  Println (count);
  //code
   }
  </code></pre>
  
  <p>I am seeing all the logs in my console but after around 17k  it starts throwing exceptions</p>
  
  <p>Something like : aws sdk exception : port already in use.</p>
  
  <p>Why do i see this exception and how do. I get rid of it?</p>
  
  <p>I tried looking on the internet for it. Couldn't find anything.</p>
  
  <p>My setting :</p>
  
  <p>Concurrency 50-100</p>
  
  <p>Set messages per task :50</p>
  
  <p>Client acknowledged</p>
  
  <pre><code>timestamp=10:27:57.183, level=WARN , logger=c.a.s.j.SQSMessageConsumerPrefetch, message={ConsumerPrefetchThread-30} Encountered exception during receive in ConsumerPrefetch thread,
  javax.jms.JMSException: AmazonClientException: receiveMessage.
      at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.handleException(AmazonSQSMessagingClientWrapper.java:422)
      at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.receiveMessage(AmazonSQSMessagingClientWrapper.java:339)
      at com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch.getMessages(SQSMessageConsumerPrefetch.java:248)
      at com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch.run(SQSMessageConsumerPrefetch.java:207)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: com.amazonaws.SdkClientException: Unable to execute HTTP request: Address already in use: connect
  </code></pre>
  
  <p>Update : i looked for the problem and it seems that new sockets are being created until every sockets gets exhausted. </p>
  
  <p>My spring jms version would be 4.3.10</p>
  
  <p>To replicate this problem just do the above configuration with the max connection as 200 and currency set to 50-100 and push some 40k messages to the sqs queue.. One can use <a href="https://github.com/adamw/elasticmq" rel="nofollow noreferrer">https://github.com/adamw/elasticmq</a> this as a local stack server which replicates Amazon sqs.. After being done till here. Comment jms listener and use soap ui load testing and call the send message to fire many messages. Just because you commented @jmslistener annotation, it won't consume messages from queue. Once you see that you have sent 40k messages, stop. Uncomment @jmslistener and restart the server.</p>
  
  <p>Update :</p>
  
  <pre><code>DefaultJmsListenerContainerFactory factory =
                  new DefaultJmsListenerContainerFactory();
          factory.setConnectionFactory(connectionFactory);
          factory.setDestinationResolver(new DynamicDestinationResolver());
          factory.setErrorHandler(Throwable::printStackTrace);
          factory.setConcurrency("50-100");
          factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
          return factory;
  </code></pre>
  
  <p>Update :</p>
  
  <pre><code>SQSConnectionFactory connectionFactory = new SQSConnectionFactory( new ProviderConfiguration(), amazonSQSclient);
  </code></pre>
  
  <p>Update :</p>
  
  <p>Client configuration details :</p>
  
  <pre><code>Protocol : HTTP
  Max connections : 200
  </code></pre>
  
  <p>Update :</p>
  
  <p>I used cache connection factory class and it seems. I read on stack overflow and in their official documentation to not use cache connection factory class and default jms listener container factory.</p>
  
  <p><a href="https://stackoverflow.com/a/21989895/5871514">https://stackoverflow.com/a/21989895/5871514</a></p>
  
  <p>It's gives the same error that i got before though.</p>
  
  <p><strong>update</strong></p>
  
  <p>My goal is to get a 500 tps, i.e i should be able to consume that much.. So i tried this method and it seems I can reach 100-200, but not  more than that.. Plus this thing is a blocker at high concurrency .. If you use it.. If you have some better solution to achieve it.. I am all ears.</p>
  
  <p>**updated **</p>
  
  <p>I am using amazonsqsclient</p>