Interface EventBus

All Known Implementing Classes:
LocalEventBus, SocketEventBus

public interface EventBus
Defines a simple event bus mechanism for message-based communication between components and/or services.

Implementations of this interface allow registering handlers and sending or publishing messages to specific addresses.

The event bus supports two messaging patterns:

  • Send: Delivers a message to a single handler registered for the given address.
  • Publish: Broadcasts a message to all handlers registered for the given address.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    publish(String address, Object message)
    Publishes a message to all handlers registered for the given address.
    void
    register(String address, Consumer<Object> handler)
    Registers a handler for messages sent to the specified address.
    void
    send(String address, Object message)
    Sends a message to a single handler registered for the given address.
    void
    Shutdown method of the EventBus.
  • Method Details

    • register

      void register(String address, Consumer<Object> handler)
      Registers a handler for messages sent to the specified address.
      Parameters:
      address - the address to listen on
      handler - a Consumer that processes incoming messages
    • send

      void send(String address, Object message)
      Sends a message to a single handler registered for the given address.
      Parameters:
      address - the target address
      message - the message to send
    • publish

      void publish(String address, Object message)
      Publishes a message to all handlers registered for the given address.
      Parameters:
      address - the target address
      message - the message to broadcast
    • shutdown

      void shutdown()
      Shutdown method of the EventBus. Depending on the implementation, this should stop all workers.