io.vertx.core.eventbus.MessageConsumer Maven / Gradle / Ivy
/*
* Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core.eventbus;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.streams.ReadStream;
/**
* An event bus consumer object representing a stream of message to an {@link EventBus} address that can
* be read from.
*
* The {@link EventBus#consumer(String)} or {@link EventBus#localConsumer(String)}
* creates a new consumer, the returned consumer is not yet registered against the event bus. Registration
* is effective after the {@link #handler(io.vertx.core.Handler)} method is invoked.
*
* The consumer is unregistered from the event bus using the {@link #unregister()} method or by calling the
* {@link #handler(io.vertx.core.Handler)} with a null value..
*
* @author Nick Scavelli
*/
@VertxGen
public interface MessageConsumer extends ReadStream> {
@Override
MessageConsumer exceptionHandler(Handler handler);
@Override
MessageConsumer handler(Handler> handler);
@Override
MessageConsumer pause();
@Override
MessageConsumer resume();
@Override
MessageConsumer fetch(long amount);
@Override
MessageConsumer endHandler(Handler endHandler);
/**
* @return a read stream for the body of the message stream.
*/
ReadStream bodyStream();
/**
* @return true if the current consumer is registered
*/
boolean isRegistered();
/**
* @return The address the handler was registered with.
*/
String address();
/**
* Set the number of messages this registration will buffer when this stream is paused. The default
* value is 1000
.
*
* When a new value is set, buffered messages may be discarded to reach the new value. The most recent
* messages will be kept.
*
* @param maxBufferedMessages the maximum number of messages that can be buffered
* @return this registration
*/
MessageConsumer setMaxBufferedMessages(int maxBufferedMessages);
/**
* @return the maximum number of messages that can be buffered when this stream is paused
*/
int getMaxBufferedMessages();
/**
* Optional method which can be called to indicate when the registration has been propagated across the cluster.
*
* @param completionHandler the completion handler
*/
void completionHandler(Handler> completionHandler);
/**
* Unregisters the handler which created this registration
*/
Future unregister();
/**
* Unregisters the handler which created this registration
*
* @param completionHandler the handler called when the unregister is done. For example in a cluster when all nodes of the
* event bus have been unregistered.
*/
void unregister(Handler> completionHandler);
}