Skip to content

Commit 0bb1db3

Browse files
committed
Add Javadoc for SubscriptionListener
References #38
1 parent 03825a9 commit 0bb1db3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/main/java/com/rabbitmq/stream/ConsumerBuilder.java

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public interface ConsumerBuilder {
6464
*/
6565
ConsumerBuilder name(String name);
6666

67+
/**
68+
* Callback on subscription.
69+
*
70+
* <p>Can be used to set the offset specification before subscribing to the stream.
71+
*
72+
* @see SubscriptionListener
73+
* @param subscriptionListener the listener
74+
* @return this builder instance
75+
*/
6776
ConsumerBuilder subscriptionListener(SubscriptionListener subscriptionListener);
6877

6978
/**

src/main/java/com/rabbitmq/stream/SubscriptionListener.java

+39
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,53 @@
1313
1414
package com.rabbitmq.stream;
1515

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+
*/
1622
public interface SubscriptionListener {
1723

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+
*/
1836
void preSubscribe(SubscriptionContext subscriptionContext);
1937

38+
/** Context object for the subscription. */
2039
interface SubscriptionContext {
2140

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+
*/
2254
OffsetSpecification offsetSpecification();
2355

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+
*/
2463
void offsetSpecification(OffsetSpecification offsetSpecification);
2564
}
2665
}

0 commit comments

Comments
 (0)