2525import com .github .sonus21 .rqueue .test .dto .FeedGeneration ;
2626import com .github .sonus21 .rqueue .test .dto .Job ;
2727import com .github .sonus21 .rqueue .test .dto .Notification ;
28+ import com .github .sonus21 .rqueue .test .dto .PeriodicJob ;
2829import com .github .sonus21 .rqueue .test .dto .Reservation ;
2930import com .github .sonus21 .rqueue .test .dto .ReservationRequest ;
3031import com .github .sonus21 .rqueue .test .dto .Sms ;
3637import lombok .RequiredArgsConstructor ;
3738import lombok .extern .slf4j .Slf4j ;
3839import org .springframework .beans .factory .annotation .Autowired ;
40+ import org .springframework .beans .factory .annotation .Value ;
3941import org .springframework .messaging .handler .annotation .Header ;
4042import org .springframework .messaging .handler .annotation .Payload ;
4143import org .springframework .stereotype .Component ;
@@ -49,13 +51,46 @@ public class MessageListener {
4951 @ NonNull private ConsumedMessageService consumedMessageService ;
5052 @ NonNull private FailureManager failureManager ;
5153
54+ @ Value ("${job.queue.name}" )
55+ private String jobQueue ;
56+
57+ @ Value ("${notification.queue.name}" )
58+ private String notificationQueueName ;
59+
60+ @ Value ("${email.queue.name}" )
61+ private String emailQueue ;
62+
63+ @ Value ("${sms.queue}" )
64+ private String smsQueue ;
65+
66+ @ Value ("${chat.indexing.queue}" )
67+ private String chatIndexingQueue ;
68+
69+ @ Value ("${feed.generation.queue}" )
70+ private String feedGenerationQueue ;
71+
72+ @ Value ("${reservation.queue}" )
73+ private String reservationQueue ;
74+
75+ @ Value ("${reservation.request.queue.name}" )
76+ private String reservationRequestQueue ;
77+
78+ @ Value ("${reservation.request.dead.letter.queue.name}" )
79+ private String reservationRequestDeadLetterQueue ;
80+
81+ @ Value ("${list.email.queue.name}" )
82+ private String listEmailQueue ;
83+
84+ @ Value ("${periodic.job.queue.name}" )
85+ private String periodicJobQueue ;
86+
5287 @ RqueueListener (value = "${job.queue.name}" , active = "${job.queue.active}" )
5388 public void onMessage (Job job ) throws Exception {
5489 log .info ("Job: {}" , job );
5590 if (failureManager .shouldFail (job .getId ())) {
5691 throw new Exception ("Failing job task to be retried" + job );
5792 }
58- consumedMessageService .save (job , null );
93+ consumedMessageService .save (job , null , jobQueue );
5994 }
6095
6196 @ RqueueListener (
@@ -69,7 +104,7 @@ public void onMessage(
69104 if (failureManager .shouldFail (notification .getId ())) {
70105 throw new Exception ("Failing notification task to be retried" + notification );
71106 }
72- consumedMessageService .save (notification , null );
107+ consumedMessageService .save (notification , null , notificationQueueName );
73108 }
74109
75110 @ RqueueListener (
@@ -84,7 +119,7 @@ public void onMessage(Email email, @Header(RqueueMessageHeaders.MESSAGE) RqueueM
84119 if (failureManager .shouldFail (email .getId ())) {
85120 throw new Exception ("Failing email task to be retried" + email );
86121 }
87- consumedMessageService .save (email , null );
122+ consumedMessageService .save (email , null , emailQueue );
88123 }
89124
90125 @ RqueueListener (
@@ -98,7 +133,7 @@ public void onMessage(Sms sms) throws Exception {
98133 if (failureManager .shouldFail (sms .getId ())) {
99134 throw new Exception ("Failing sms task to be retried" + sms );
100135 }
101- consumedMessageService .save (sms , null );
136+ consumedMessageService .save (sms , null , smsQueue );
102137 }
103138
104139 @ RqueueListener (
@@ -112,7 +147,7 @@ public void onMessage(ChatIndexing chatIndexing) throws Exception {
112147 if (failureManager .shouldFail (chatIndexing .getId ())) {
113148 throw new Exception ("Failing chat indexing task to be retried" + chatIndexing );
114149 }
115- consumedMessageService .save (chatIndexing , null );
150+ consumedMessageService .save (chatIndexing , null , chatIndexingQueue );
116151 }
117152
118153 @ RqueueListener (
@@ -126,7 +161,7 @@ public void onMessage(FeedGeneration feedGeneration) throws Exception {
126161 if (failureManager .shouldFail (feedGeneration .getId ())) {
127162 throw new Exception ("Failing feedGeneration task to be retried" + feedGeneration );
128163 }
129- consumedMessageService .save (feedGeneration , null );
164+ consumedMessageService .save (feedGeneration , null , feedGenerationQueue );
130165 }
131166
132167 @ RqueueListener (
@@ -140,7 +175,7 @@ public void onMessage(Reservation reservation) throws Exception {
140175 if (failureManager .shouldFail (reservation .getId ())) {
141176 throw new Exception ("Failing reservation task to be retried" + reservation );
142177 }
143- consumedMessageService .save (reservation , null );
178+ consumedMessageService .save (reservation , null , reservationQueue );
144179 }
145180
146181 @ RqueueListener (
@@ -154,7 +189,7 @@ public void onMessageReservationRequest(ReservationRequest request) throws Excep
154189 if (failureManager .shouldFail (request .getId ())) {
155190 throw new Exception ("Failing reservation request task to be retried" + request );
156191 }
157- consumedMessageService .save (request , null );
192+ consumedMessageService .save (request , null , reservationRequestQueue );
158193 }
159194
160195 @ RqueueListener (
@@ -164,15 +199,29 @@ public void onMessageReservationRequest(ReservationRequest request) throws Excep
164199 public void onMessageReservationRequestDeadLetterQueue (ReservationRequest request )
165200 throws Exception {
166201 log .info ("ReservationRequest Dead Letter Queue{}" , request );
167- consumedMessageService .save (request , "reservation-request-dlq" );
202+ consumedMessageService .save (
203+ request , "reservation-request-dlq" , reservationRequestDeadLetterQueue );
168204 }
169205
170206 @ RqueueListener (value = "${list.email.queue.name}" , active = "${list.email.queue.enabled}" )
171207 public void onMessageEmailList (List <Email > emailList ) throws JsonProcessingException {
172208 log .info ("onMessageEmailList {}" , emailList );
173209 String consumedId = UUID .randomUUID ().toString ();
174210 for (Email email : emailList ) {
175- consumedMessageService .save (email , consumedId );
211+ consumedMessageService .save (email , consumedId , listEmailQueue );
212+ }
213+ }
214+
215+ @ RqueueListener (
216+ value = "${periodic.job.queue.name}" ,
217+ active = "${periodic.job.queue.active}" ,
218+ deadLetterQueue = "${periodic.job.dead.letter.queue.name}" ,
219+ numRetries = "${periodic.job.queue.retry.count}" )
220+ public void onPeriodicJob (PeriodicJob periodicJob ) throws Exception {
221+ log .info ("onPeriodicJob: {}" , periodicJob );
222+ if (failureManager .shouldFail (periodicJob .getId ())) {
223+ throw new Exception ("Failing PeriodicJob task to be retried" + periodicJob );
176224 }
225+ consumedMessageService .save (periodicJob , UUID .randomUUID ().toString (), periodicJobQueue );
177226 }
178227}
0 commit comments