java.lang.Object
org.miaixz.bus.http.Stomp
A STOMP protocol client over WebSocket.
This class provides functionality for connecting to a STOMP server, sending messages, subscribing to topics and queues, and acknowledging messages. It supports both automatic and client-side message acknowledgment.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a STOMP header.static classRepresents a STOMP message. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidack(Stomp.Message message) Acknowledges the receipt of a message.connect()Connects to the STOMP server.connect(List<Stomp.Header> headers) Connects to the STOMP server with the specified headers.voidDisconnects from the STOMP server.static Stompover(CoverCall.Client task) Creates a STOMP client with automatic message acknowledgment.static Stompover(CoverCall.Client task, boolean autoAck) Creates a STOMP client with a specified acknowledgment mode.queue(String destination, List<Stomp.Header> headers, Callback<Stomp.Message> callback) Subscribes to a queue with additional headers.queue(String destination, Callback<Stomp.Message> callback) Subscribes to a queue.voidsend(Stomp.Message message) Sends a STOMP message to the server.voidSends a message to the specified destination.voidsetLegacyWhitespace(boolean legacyWhitespace) Sets whether to use legacy whitespace formatting.setOnConnected(Callback<Stomp> onConnected) Sets the callback for when the connection is successfully established.setOnDisconnected(Callback<CoverCall.Close> onDisconnected) Sets the callback for when the connection is disconnected.setOnError(Callback<Stomp.Message> onError) Sets the callback for error messages.subscribe(String destination, List<Stomp.Header> headers, Callback<Stomp.Message> callback) Subscribes to a destination.topic(String destination, List<Stomp.Header> headers, Callback<Stomp.Message> callback) Subscribes to a topic with additional headers.topic(String destination, Callback<Stomp.Message> callback) Subscribes to a topic.voidUnsubscribes from a queue.voidunsubscribe(String destination) Unsubscribes from a destination.voidUnsubscribes from a topic.
-
Field Details
-
SUPPORTED_VERSIONS
The supported STOMP protocol versions.- See Also:
-
AUTO_ACK
The automatic acknowledgment mode.- See Also:
-
CLIENT_ACK
The client-side acknowledgment mode.- See Also:
-
-
Method Details
-
over
Creates a STOMP client with automatic message acknowledgment.- Parameters:
task- The underlying WebSocket client.- Returns:
- a new
Stompinstance.
-
over
Creates a STOMP client with a specified acknowledgment mode.- Parameters:
task- The underlying WebSocket client.autoAck- Whether to automatically acknowledge messages.- Returns:
- a new
Stompinstance.
-
connect
Connects to the STOMP server.- Returns:
- this
Stompinstance.
-
connect
Connects to the STOMP server with the specified headers.- Parameters:
headers- The STOMP headers for the connection.- Returns:
- this
Stompinstance.
-
disconnect
public void disconnect()Disconnects from the STOMP server. -
setOnConnected
Sets the callback for when the connection is successfully established.- Parameters:
onConnected- The connection callback.- Returns:
- this
Stompinstance.
-
setOnDisconnected
Sets the callback for when the connection is disconnected.- Parameters:
onDisconnected- The disconnection callback.- Returns:
- this
Stompinstance.
-
setOnError
Sets the callback for error messages.- Parameters:
onError- The error callback.- Returns:
- this
Stompinstance.
-
sendTo
Sends a message to the specified destination.- Parameters:
destination- The destination to send the message to.data- The message payload.
-
send
Sends a STOMP message to the server.- Parameters:
message- The STOMP message to send.- Throws:
IllegalArgumentException- if theconnectmethod has not been called.
-
topic
Subscribes to a topic.- Parameters:
destination- The topic destination.callback- The callback for received messages.- Returns:
- this
Stompinstance.
-
topic
public Stomp topic(String destination, List<Stomp.Header> headers, Callback<Stomp.Message> callback) Subscribes to a topic with additional headers.- Parameters:
destination- The topic destination.headers- Additional headers for the subscription.callback- The callback for received messages.- Returns:
- this
Stompinstance.
-
queue
Subscribes to a queue.- Parameters:
destination- The queue destination.callback- The callback for received messages.- Returns:
- this
Stompinstance.
-
queue
public Stomp queue(String destination, List<Stomp.Header> headers, Callback<Stomp.Message> callback) Subscribes to a queue with additional headers.- Parameters:
destination- The queue destination.headers- Additional headers for the subscription.callback- The callback for received messages.- Returns:
- this
Stompinstance.
-
subscribe
public Stomp subscribe(String destination, List<Stomp.Header> headers, Callback<Stomp.Message> callback) Subscribes to a destination.- Parameters:
destination- The destination to subscribe to.headers- Additional headers for the subscription.callback- The callback for received messages.- Returns:
- this
Stompinstance.
-
ack
Acknowledges the receipt of a message.- Parameters:
message- The message received from the server.
-
untopic
Unsubscribes from a topic.- Parameters:
destination- The topic destination.
-
unqueue
Unsubscribes from a queue.- Parameters:
destination- The queue destination.
-
unsubscribe
Unsubscribes from a destination.- Parameters:
destination- The destination to unsubscribe from.
-
setLegacyWhitespace
public void setLegacyWhitespace(boolean legacyWhitespace) Sets whether to use legacy whitespace formatting.- Parameters:
legacyWhitespace-trueto enable legacy formatting.
-