13
13
14
14
package com .rabbitmq .stream .impl ;
15
15
16
+ import com .rabbitmq .stream .Constants ;
16
17
import com .rabbitmq .stream .MessageHandler .Context ;
18
+ import com .rabbitmq .stream .StreamException ;
17
19
import com .rabbitmq .stream .impl .StreamConsumerBuilder .TrackingConfiguration ;
18
20
import java .time .Duration ;
19
21
import java .util .Collection ;
@@ -91,7 +93,11 @@ Registration registerTrackingConsumer(
91
93
}
92
94
Tracker t = iterator .next ();
93
95
if (t .consumer ().isOpen ()) {
94
- t .flushIfNecessary ();
96
+ try {
97
+ t .flushIfNecessary ();
98
+ } catch (Exception e ) {
99
+ LOGGER .info ("Error while flushing tracker: {}" , e .getMessage ());
100
+ }
95
101
} else {
96
102
iterator .remove ();
97
103
}
@@ -194,10 +200,18 @@ public Consumer<Context> postProcessingCallback() {
194
200
public void flushIfNecessary () {
195
201
if (this .count > 0 ) {
196
202
if (this .clock .time () - this .lastTrackingActivity > this .flushIntervalInNs ) {
197
- long lastStoredOffset = consumer .lastStoredOffset ();
198
- if (Long .compareUnsigned (lastStoredOffset , lastProcessedOffset ) < 0 ) {
199
- this .consumer .store (this .lastProcessedOffset );
200
- this .lastTrackingActivity = clock .time ();
203
+ try {
204
+ long lastStoredOffset = consumer .lastStoredOffset ();
205
+ if (Long .compareUnsigned (lastStoredOffset , lastProcessedOffset ) < 0 ) {
206
+ this .consumer .store (this .lastProcessedOffset );
207
+ this .lastTrackingActivity = clock .time ();
208
+ }
209
+ } catch (StreamException e ) {
210
+ if (e .getCode () == Constants .RESPONSE_CODE_NO_OFFSET ) {
211
+ // probably nothing stored yet, let it go
212
+ } else {
213
+ throw e ;
214
+ }
201
215
}
202
216
}
203
217
}
@@ -216,15 +230,23 @@ public LongConsumer trackingCallback() {
216
230
@ Override
217
231
public Runnable closingCallback () {
218
232
return () -> {
219
- long lastStoredOffset = consumer .lastStoredOffset ();
220
- if (Long .compareUnsigned (lastStoredOffset , lastProcessedOffset ) < 0 ) {
221
- LOGGER .debug ("Storing offset before closing" );
222
- this .consumer .store (this .lastProcessedOffset );
223
- } else {
224
- LOGGER .debug (
225
- "Not storing offset before closing because last stored offset after last processed offset: {} > {}" ,
226
- lastStoredOffset ,
227
- lastProcessedOffset );
233
+ try {
234
+ long lastStoredOffset = consumer .lastStoredOffset ();
235
+ if (Long .compareUnsigned (lastStoredOffset , lastProcessedOffset ) < 0 ) {
236
+ LOGGER .debug ("Storing offset before closing" );
237
+ this .consumer .store (this .lastProcessedOffset );
238
+ } else {
239
+ LOGGER .debug (
240
+ "Not storing offset before closing because last stored offset after last processed offset: {} > {}" ,
241
+ lastStoredOffset ,
242
+ lastProcessedOffset );
243
+ }
244
+ } catch (StreamException e ) {
245
+ if (e .getCode () == Constants .RESPONSE_CODE_NO_OFFSET ) {
246
+ // probably nothing stored yet, let it go
247
+ } else {
248
+ throw e ;
249
+ }
228
250
}
229
251
};
230
252
}
@@ -253,10 +275,18 @@ public Consumer<Context> postProcessingCallback() {
253
275
@ Override
254
276
public void flushIfNecessary () {
255
277
if (this .clock .time () - this .lastTrackingActivity > this .checkIntervalInNs ) {
256
- long lastStoredOffset = consumer .lastStoredOffset ();
257
- if (Long .compareUnsigned (lastStoredOffset , lastRequestedOffset ) < 0 ) {
258
- this .consumer .store (this .lastRequestedOffset );
259
- this .lastTrackingActivity = clock .time ();
278
+ try {
279
+ long lastStoredOffset = consumer .lastStoredOffset ();
280
+ if (Long .compareUnsigned (lastStoredOffset , lastRequestedOffset ) < 0 ) {
281
+ this .consumer .store (this .lastRequestedOffset );
282
+ this .lastTrackingActivity = clock .time ();
283
+ }
284
+ } catch (StreamException e ) {
285
+ if (e .getCode () == Constants .RESPONSE_CODE_NO_OFFSET ) {
286
+ // probably nothing stored yet, let it go
287
+ } else {
288
+ throw e ;
289
+ }
260
290
}
261
291
}
262
292
}
0 commit comments