- All Superinterfaces:
AutoCloseable,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 TypeMethodDescriptiondefault voidlisten(MessageHandler messageHandler) Continuously subscribes to messages in an asynchronous manner.voidsubscribe(MessageHandler messageHandler) Subscribes to a single message and processes it using the provided message handler.
-
Method Details
-
subscribe
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- TheMessageHandlerto process the received message.
-
listen
Continuously subscribes to messages in an asynchronous manner. This method starts a new thread that constantly listens for and processes messages using the givenMessageHandler. The loop runs indefinitely until the consumer is closed.- Parameters:
messageHandler- TheMessageHandlerto process the received messages.
-