vertx / io.vertx.core.eventbus / EventBus

EventBus

interface EventBus : Measured

A Vert.x event-bus is a light-weight distributed messaging system which allows different parts of your application, or different applications and services to communicate with each in a loosely coupled way.

An event-bus supports publish-subscribe messaging, point-to-point messaging and request-response messaging.

Message delivery is best-effort and messages can be lost if failure of all or part of the event bus occurs.

Please refer to the documentation for more information on the event bus.

Author
Tim Fox

Functions

addInterceptor

abstract fun addInterceptor(interceptor: Handler<SendContext<Any>>): EventBus

Add an interceptor that will be called whenever a message is sent from Vert.x

close

abstract fun close(completionHandler: Handler<AsyncResult<Void>>): Unit

Close the event bus and release any resources held. This would not normally be called in user code

consumer

abstract fun <T : Any> consumer(address: String): MessageConsumer<T>

Create a message consumer against the specified address.

The returned consumer is not yet registered at the address, registration will be effective when MessageConsumer#handler(io.vertx.core.Handler) is called.

abstract fun <T : Any> consumer(address: String, handler: Handler<Message<T>>): MessageConsumer<T>

Create a consumer and register it against the specified address.

localConsumer

abstract fun <T : Any> localConsumer(address: String): MessageConsumer<T>

Like #consumer(String) but the address won't be propagated across the cluster.

abstract fun <T : Any> localConsumer(address: String, handler: Handler<Message<T>>): MessageConsumer<T>

Like #consumer(String, Handler) but the address won't be propagated across the cluster.

publish

abstract fun publish(address: String, message: Any): EventBus

Publish a message.

The message will be delivered to all handlers registered to the address.

abstract fun publish(address: String, message: Any, options: DeliveryOptions): EventBus

Like #publish(String, Object) but specifying options that can be used to configure the delivery.

publisher

abstract fun <T : Any> publisher(address: String): MessageProducer<T>

Create a message publisher against the specified address.

The returned publisher will invoke the #publish(String, Object) method when the stream io.vertx.core.streams.WriteStream#write(Object) method is called with the publisher address and the provided data.

abstract fun <T : Any> publisher(address: String, options: DeliveryOptions): MessageProducer<T>

Like #publisher(String) but specifying delivery options that will be used for configuring the delivery of the message.

registerCodec

abstract fun registerCodec(codec: MessageCodec<Any, Any>): EventBus

Register a message codec.

You can register a message codec if you want to send any non standard message across the event bus. E.g. you might want to send POJOs directly across the event bus.

To use a message codec for a send, you should specify it in the delivery options.

registerDefaultCodec

abstract fun <T : Any> registerDefaultCodec(clazz: Class<T>, codec: MessageCodec<T, *>): EventBus

Register a default message codec.

You can register a message codec if you want to send any non standard message across the event bus. E.g. you might want to send POJOs directly across the event bus.

Default message codecs will be used to serialise any messages of the specified type on the event bus without the codec having to be specified in the delivery options.

removeInterceptor

abstract fun removeInterceptor(interceptor: Handler<SendContext<Any>>): EventBus

Remove an interceptor

send

abstract fun send(address: String, message: Any): EventBus

Sends a message.

The message will be delivered to at most one of the handlers registered to the address.

abstract fun <T : Any> send(address: String, message: Any, replyHandler: Handler<AsyncResult<Message<T>>>): EventBus

Like #send(String, Object) but specifying a replyHandler that will be called if the recipient subsequently replies to the message.

abstract fun send(address: String, message: Any, options: DeliveryOptions): EventBus

Like #send(String, Object) but specifying options that can be used to configure the delivery.

abstract fun <T : Any> send(address: String, message: Any, options: DeliveryOptions, replyHandler: Handler<AsyncResult<Message<T>>>): EventBus

Like #send(String, Object, DeliveryOptions) but specifying a replyHandler that will be called if the recipient subsequently replies to the message.

sender

abstract fun <T : Any> sender(address: String): MessageProducer<T>

Create a message sender against the specified address.

The returned sender will invoke the #send(String, Object) method when the stream io.vertx.core.streams.WriteStream#write(Object) method is called with the sender address and the provided data.

abstract fun <T : Any> sender(address: String, options: DeliveryOptions): MessageProducer<T>

Like #sender(String) but specifying delivery options that will be used for configuring the delivery of the message.

start

abstract fun start(completionHandler: Handler<AsyncResult<Void>>): Unit

Start the event bus. This would not normally be called in user code

unregisterCodec

abstract fun unregisterCodec(name: String): EventBus

Unregister a message codec.

unregisterDefaultCodec

abstract fun unregisterDefaultCodec(clazz: Class<Any>): EventBus

Unregister a default message codec.