amazon web services - Spring AWS SQS Reconnect After Losing Connection -
i using spring cloud aws (1.0.1.release) spring boot run sqs consumer. application runs fine, when looses network connection (for instance if switch wifi off on laptop when runs on it), see errors on console , application never recovers. hangs there , not reconnect after network becomes available. have kill , bring up. how force recover itself?
// spring boot entry point: public static void main(string[] args) { springapplication.run(myconsumerconfiguration.class, args); } // message listener (a different class) @messagemapping(value = "mylogicalqueuename" ) public void receive(mypojo object) { }
the error see @ console:
exception in thread "simplemessagelistenercontainer-1" com.amazonaws.amazonclientexception: unable execute http request: sqs.us-east-1.amazonaws.com @ com.amazonaws.http.amazonhttpclient.executehelper(amazonhttpclient.java:473) @ com.amazonaws.http.amazonhttpclient.execute(amazonhttpclient.java:297) @ com.amazonaws.services.sqs.amazonsqsclient.invoke(amazonsqsclient.java:2422) @ com.amazonaws.services.sqs.amazonsqsclient.receivemessage(amazonsqsclient.java:1130) @ com.amazonaws.services.sqs.amazonsqsasyncclient$23.call(amazonsqsasyncclient.java:1678) @ com.amazonaws.services.sqs.amazonsqsasyncclient$23.call(amazonsqsasyncclient.java:1676) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745
i figured out problem why sqs not able reconnect after network connection lost.
actually seems problem in current spring aws implementation of org.springframework.cloud.aws.messaging.listener.simplemessagelistenercontainer.java
private class asynchronousmessagelistener implements runnable { private final queueattributes queueattributes; private final string logicalqueuename; private asynchronousmessagelistener(string logicalqueuename, queueattributes queueattributes) { this.logicalqueuename = logicalqueuename; this.queueattributes = queueattributes; } @override public void run() { while (isrunning()) { receivemessageresult receivemessageresult = getamazonsqs().receivemessage(this.queueattributes.getreceivemessagerequest()); countdownlatch messagebatchlatch = new countdownlatch(receivemessageresult.getmessages().size()); (message message : receivemessageresult.getmessages()) { if (isrunning()) { messageexecutor messageexecutor = new messageexecutor(this.logicalqueuename, message, this.queueattributes); gettaskexecutor().execute(new signalexecutingrunnable(messagebatchlatch, messageexecutor)); } else { break; } } try { messagebatchlatch.await(); } catch (interruptedexception e) { thread.currentthread().interrupt(); } } } }
above code spins new thread polling sqs queue grab messages. once network connection dropped getamazonsqs().receivemessage(this.queueattributes.getreceivemessagerequest())
throws unknownhostexception
, not handled in code , causes thread termination. when network connection established later on, there no thread polling queue retrieve data.
i have raised issue spring this. following link: https://github.com/spring-cloud/spring-cloud-aws/issues/82
hope explains all.
Comments
Post a Comment