|
13 | 13 |
|
14 | 14 | package com.rabbitmq.stream;
|
15 | 15 |
|
| 16 | +/** |
| 17 | + * Callback interface to customize a subscription. |
| 18 | + * |
| 19 | + * <p>It is possible to change the computed {@link OffsetSpecification} in {@link |
| 20 | + * #preSubscribe(SubscriptionContext)} by using a custom offset tracking strategy. |
| 21 | + */ |
16 | 22 | public interface SubscriptionListener {
|
17 | 23 |
|
| 24 | + /** |
| 25 | + * Callback called before the subscription is created. |
| 26 | + * |
| 27 | + * <p>The method is called when a {@link Consumer} is created and it registers to broker, and also |
| 28 | + * when the subscription must be re-created (after a disconnection or when the subscription must |
| 29 | + * moved because the stream member it was connection becomes unavailable). |
| 30 | + * |
| 31 | + * <p>Application code can set the {@link OffsetSpecification} that will be used with the {@link |
| 32 | + * SubscriptionContext#offsetSpecification(OffsetSpecification)} method. |
| 33 | + * |
| 34 | + * @param subscriptionContext |
| 35 | + */ |
18 | 36 | void preSubscribe(SubscriptionContext subscriptionContext);
|
19 | 37 |
|
| 38 | + /** Context object for the subscription. */ |
20 | 39 | interface SubscriptionContext {
|
21 | 40 |
|
| 41 | + /** |
| 42 | + * The offset specification computed by the library. |
| 43 | + * |
| 44 | + * <p>If the consumer has no name, the value is the value set with {@link |
| 45 | + * ConsumerBuilder#offset(OffsetSpecification)} on the first subscription and the offset of the |
| 46 | + * last dispatched message on subsequent calls (e.g. when the client re-subscribes after a |
| 47 | + * disconnection). |
| 48 | + * |
| 49 | + * <p>If the consumer has a name, the value is the last stored if any. |
| 50 | + * |
| 51 | + * @see ConsumerBuilder#name(String) |
| 52 | + * @return the computed offset specification |
| 53 | + */ |
22 | 54 | OffsetSpecification offsetSpecification();
|
23 | 55 |
|
| 56 | + /** |
| 57 | + * Set the offset specification to use for the subscription. |
| 58 | + * |
| 59 | + * <p>It overrides the value computed by the client. |
| 60 | + * |
| 61 | + * @param offsetSpecification the offset specification to use |
| 62 | + */ |
24 | 63 | void offsetSpecification(OffsetSpecification offsetSpecification);
|
25 | 64 | }
|
26 | 65 | }
|
0 commit comments