Skip to content

Commit c82cae0

Browse files
committed
Add Javadoc for single active consumer API
References #46
1 parent 2210495 commit c82cae0

11 files changed

+102
-11
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").
@@ -34,5 +34,11 @@ public interface Consumer extends AutoCloseable {
3434
@Override
3535
void close();
3636

37+
/**
38+
* The stored offset for this named consumer on the configured stream.
39+
*
40+
* @return stored offset
41+
* @since 0.6.0
42+
*/
3743
long storedOffset();
3844
}

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

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").
@@ -29,10 +29,15 @@ public interface ConsumerBuilder {
2929
/**
3030
* Set the consumer to consume from a super stream (partitioned stream).
3131
*
32+
* <p>This is meant to be used with {@link #singleActiveConsumer()}.
33+
*
3234
* <p>This is an experimental API, subject to change.
3335
*
36+
* <p>RabbitMQ 3.11 or more is required.
37+
*
3438
* @param superStream
3539
* @return this builder instance
40+
* @see #singleActiveConsumer()
3641
*/
3742
ConsumerBuilder superStream(String superStream);
3843

@@ -64,8 +69,45 @@ public interface ConsumerBuilder {
6469
*/
6570
ConsumerBuilder name(String name);
6671

72+
/**
73+
* Declare the consumer as a single active consumer.
74+
*
75+
* <p>A single active consumer must set up a name with {@link #name(String)}.
76+
*
77+
* <p>Instances of the same application can declare several single active consumer instances with
78+
* the same name and only one will be active at a time, meaning it will be the only one to get
79+
* messages from the broker.
80+
*
81+
* <p>If the active consumer instance stops or crashes, the broker will choose a new active
82+
* instance among the remaining ones.
83+
*
84+
* <p>This is an experimental API, subject to change.
85+
*
86+
* <p>RabbitMQ 3.11 or more is required.
87+
*
88+
* @return this builder instance
89+
* @since 0.6.0
90+
* @see #name(String)
91+
*/
6792
ConsumerBuilder singleActiveConsumer();
6893

94+
/**
95+
* Set the listener for single active consumer updates.
96+
*
97+
* <p>This listener is usually set when manual offset tracking is used, either server-side or with
98+
* an external datastore.
99+
*
100+
* <p>This is an experimental API, subject to change.
101+
*
102+
* <p>RabbitMQ 3.11 or more is required.
103+
*
104+
* @param consumerUpdateListener
105+
* @return this builder instance
106+
* @since 0.6.0
107+
* @see #singleActiveConsumer()
108+
* @see ConsumerUpdateListener
109+
* @see #manualTrackingStrategy()
110+
*/
69111
ConsumerBuilder consumerUpdateListener(ConsumerUpdateListener consumerUpdateListener);
70112

71113
/**
@@ -78,6 +120,7 @@ public interface ConsumerBuilder {
78120
* @see SubscriptionListener
79121
* @param subscriptionListener the listener
80122
* @return this builder instance
123+
* @since 0.5.0
81124
*/
82125
ConsumerBuilder subscriptionListener(SubscriptionListener subscriptionListener);
83126

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

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2021-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").
@@ -13,18 +13,60 @@
1313
1414
package com.rabbitmq.stream;
1515

16+
/**
17+
* An interface for reacting to status changes of single active consumers.
18+
*
19+
* <p>An application uses the {@link #update(Context)} callback to compute the offset to start
20+
* consuming from when the consumer becomes active.
21+
*
22+
* <p>The application can also use the {@link #update(Context)} callback to store the offset of the
23+
* last message it processed when the consumer goes from active to passive.
24+
*
25+
* <p>This is especially useful when using manual server-side offset tracking or offset tracking
26+
* from an external datastore.
27+
*
28+
* @see ConsumerBuilder#singleActiveConsumer()
29+
* @see ConsumerBuilder#manualTrackingStrategy()
30+
*/
1631
public interface ConsumerUpdateListener {
1732

33+
/**
34+
* Callback when the consumer status change.
35+
*
36+
* @param context information on the status change
37+
* @return the offset specification to consume from if the status is active
38+
*/
1839
OffsetSpecification update(Context context);
1940

41+
/** Information on the status change. */
2042
interface Context {
2143

44+
/**
45+
* The consumer instance.
46+
*
47+
* @return
48+
*/
2249
Consumer consumer();
2350

51+
/**
52+
* The stream (partition in a super stream) involved.
53+
*
54+
* @return
55+
*/
2456
String stream();
2557

58+
/**
59+
* The new status of the consumer.
60+
*
61+
* @return
62+
*/
2663
Status status();
2764

65+
/**
66+
* The previous status of the consumer.
67+
*
68+
* @return
69+
*/
2870
Status previousStatus();
2971
}
3072

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2021-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

src/main/java/com/rabbitmq/stream/impl/AsyncRetry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

src/main/java/com/rabbitmq/stream/impl/StreamConsumerBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

src/test/java/com/rabbitmq/stream/impl/AlarmsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2021-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

src/test/java/com/rabbitmq/stream/impl/SacStreamConsumerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2021-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

src/test/java/com/rabbitmq/stream/impl/SacSuperStreamConsumerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2021-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

src/test/java/com/rabbitmq/stream/impl/SuperStreamConsumerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2021-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").

0 commit comments

Comments
 (0)