java - SQS message acknowledgement -
my sring boot application listens amazon sqs queue. right need implement correct message acknowledgement - need receive message, business logic after in case of success need ack message(delete message queue). example, in case of error in business logic message must re-enqueued.
this sqs config:
/** * aws credentials bean */ @bean public awscredentials awscredentials() { return new basicawscredentials(accesskey, secretaccesskey); } /** * aws client bean */ @bean public amazonsqs amazonsqsasyncclient() { amazonsqs sqsclient = new amazonsqsclient(awscredentials()); sqsclient.setregion(region.getregion(regions.us_east_1)); return sqsclient; } /** * aws connection factory */ @bean public sqsconnectionfactory connectionfactory() { sqsconnectionfactory.builder factorybuilder = new sqsconnectionfactory.builder( region.getregion(regions.us_east_1)); factorybuilder.setawscredentialsprovider(new awscredentialsprovider() { @override public awscredentials getcredentials() { return awscredentials(); } @override public void refresh() { } }); return factorybuilder.build(); } /** * registering queuelistener queuename */ @bean public defaultmessagelistenercontainer defaultmessagelistenercontainer() { defaultmessagelistenercontainer messagelistenercontainer = new defaultmessagelistenercontainer(); messagelistenercontainer.setconnectionfactory(connectionfactory()); messagelistenercontainer.setmessagelistener(new messagelisteneradapter(new myqueuelistener())); messagelistenercontainer.setdestinationname(queuename); return messagelistenercontainer; }
my queue listener:
public class myqueuelistener { public void handlemessage(string messagecontent) throws jmsexception { //do job //todo: ack message } }
right don't know how ack message listener.
normally defaultmessagelistenercontainer
acknowledges message before or after execution of handlemessage
automatically. don't need anything.
but recommended defaultmessagelistenercontainer
use transactions instead of client ack mode. not sure if amazon sqs has such option.
Comments
Post a Comment