forked from rabbitmq/rabbitmq-stream-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsumerFlowControlStrategy.java
42 lines (37 loc) · 1.68 KB
/
ConsumerFlowControlStrategy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.rabbitmq.stream.flow;
import com.rabbitmq.stream.CallbackStreamDataHandler;
import com.rabbitmq.stream.OffsetSpecification;
/**
* A built and configured flow control strategy for consumers.
* Implementations may freely implement reactions to the various client callbacks.
* When defined by each implementation, it may internally call {@link CreditAsker#credit} to ask for credits.
* One instance of this is expected to be built for each separate subscription.
* A {@link com.rabbitmq.stream.Consumer} may have multiple subscriptions, and thus multiple instances of this.
*/
public interface ConsumerFlowControlStrategy extends CallbackStreamDataHandler {
/**
* Callback for handling a stream subscription.
* Called right before the subscription is sent to the broker.
* <p>
* Either this variant or {@link CallbackStreamDataHandler#handleSubscribe} should be called, NOT both.
* </p>
*
* @param offsetSpecification The offset specification for this new subscription
* @param isInitialSubscription Whether this subscription is an initial subscription
* or a recovery for an existing subscription
* @return The initial credits that should be granted to this new subscription
*/
int handleSubscribeReturningInitialCredits(
OffsetSpecification offsetSpecification,
boolean isInitialSubscription
);
@Override
default void handleSubscribe(
OffsetSpecification offsetSpecification,
boolean isInitialSubscription) {
handleSubscribeReturningInitialCredits(
offsetSpecification,
isInitialSubscription
);
}
}