Module bus.extra

Interface Consumer

All Superinterfaces:
AutoCloseable, Closeable

public interface Consumer extends Closeable
Represents a message consumer interface for Message Queue (MQ) systems. This interface defines methods for subscribing to messages, either individually or continuously, and handling them with a MessageHandler.
Since:
Java 17+
Author:
Kimi Liu
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    listen(MessageHandler messageHandler)
    Continuously subscribes to messages in an asynchronous manner.
    void
    subscribe(MessageHandler messageHandler)
    Subscribes to a single message and processes it using the provided message handler.

    Methods inherited from interface java.io.Closeable

    close
  • Method Details

    • subscribe

      void subscribe(MessageHandler messageHandler)
      Subscribes to a single message and processes it using the provided message handler. This method is typically blocking and waits for one message to arrive.
      Parameters:
      messageHandler - The MessageHandler to process the received message.
    • listen

      default void listen(MessageHandler messageHandler)
      Continuously subscribes to messages in an asynchronous manner. This method starts a new thread that constantly listens for and processes messages using the given MessageHandler. The loop runs indefinitely until the consumer is closed.
      Parameters:
      messageHandler - The MessageHandler to process the received messages.