Skip to content
Permalink
Browse files
Merge pull request #12 from tmaret/subscriber-request-documentation
Fix/extend documentation for the request builder
  • Loading branch information
cschneider committed Jan 5, 2019
2 parents 42932be + bb9923c commit 58294a9ac4a8fcaf64c6376c0c4a30e8f9212aa1
Showing 2 changed files with 30 additions and 9 deletions.
@@ -30,13 +30,10 @@ public interface Messaging {
void send(String topic, Message message);

/**
* Subscribe to a topic. The callback is called for each message received.
*
* @param topic to consume from. TODO Do we allow wild cards?
* @param position in the topic to start consuming from
* @param seek where to start from when position is not valid or null
* @param callback will be called for each message received
* @return Returned subscription must be closed by the caller to unsubscribe
* Subscribe to a topic.
* The returned subscription must be closed by the caller to unsubscribe.
*
* @param request to subscribe
*/
Subscription subscribe(SubscribeRequest request);

@@ -23,6 +23,9 @@

import javax.annotation.ParametersAreNonnullByDefault;

/**
* A Subscription request to consume messages from a topic.
*/
@ParametersAreNonnullByDefault
public final class SubscribeRequest {
private final String topic;
@@ -35,15 +38,36 @@ private SubscribeRequest(String topic, Consumer<Received> callback) {
this.callback = callback;
}

/**
* Build a subscription request for the given topic and {@code Consumer} callback.
*
* @param topic to consume from
* @param callback to be invoked for each message consumed
* @return a new subscription request
*/
public static SubscribeRequest to(String topic, Consumer<Received> callback) {
return new SubscribeRequest(topic, callback);
}


/**
* Set the {@code Position} position to start consuming from.
*
* @param position in the topic to start consuming from
* @return the updated subscribe request
*/
public SubscribeRequest startAt(Position position) {
this.position = position;
return this;
}


/**
* Set the earliest or latest position to start consuming from
* when the position is {@code null} or not valid. By default,
* seek is set to {@link Seek#latest}.
*
* @param seek where to start consuming when no valid position is specified
* @return the updated subscribe request
*/
public SubscribeRequest seek(Seek seek) {
this.seek = requireNonNull(seek, "Seek must not be null");
return this;

0 comments on commit 58294a9

Please sign in to comment.