Module bus.http

Class Stomp

java.lang.Object
org.miaixz.bus.http.Stomp

public class Stomp extends Object
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
  • Field Details

  • Method Details

    • over

      public static Stomp over(CoverCall.Client task)
      Creates a STOMP client with automatic message acknowledgment.
      Parameters:
      task - The underlying WebSocket client.
      Returns:
      a new Stomp instance.
    • over

      public static Stomp over(CoverCall.Client task, boolean autoAck)
      Creates a STOMP client with a specified acknowledgment mode.
      Parameters:
      task - The underlying WebSocket client.
      autoAck - Whether to automatically acknowledge messages.
      Returns:
      a new Stomp instance.
    • connect

      public Stomp connect()
      Connects to the STOMP server.
      Returns:
      this Stomp instance.
    • connect

      public Stomp connect(List<Stomp.Header> headers)
      Connects to the STOMP server with the specified headers.
      Parameters:
      headers - The STOMP headers for the connection.
      Returns:
      this Stomp instance.
    • disconnect

      public void disconnect()
      Disconnects from the STOMP server.
    • setOnConnected

      public Stomp setOnConnected(Callback<Stomp> onConnected)
      Sets the callback for when the connection is successfully established.
      Parameters:
      onConnected - The connection callback.
      Returns:
      this Stomp instance.
    • setOnDisconnected

      public Stomp setOnDisconnected(Callback<CoverCall.Close> onDisconnected)
      Sets the callback for when the connection is disconnected.
      Parameters:
      onDisconnected - The disconnection callback.
      Returns:
      this Stomp instance.
    • setOnError

      public Stomp setOnError(Callback<Stomp.Message> onError)
      Sets the callback for error messages.
      Parameters:
      onError - The error callback.
      Returns:
      this Stomp instance.
    • sendTo

      public void sendTo(String destination, String data)
      Sends a message to the specified destination.
      Parameters:
      destination - The destination to send the message to.
      data - The message payload.
    • send

      public void send(Stomp.Message message)
      Sends a STOMP message to the server.
      Parameters:
      message - The STOMP message to send.
      Throws:
      IllegalArgumentException - if the connect method has not been called.
    • topic

      public Stomp topic(String destination, Callback<Stomp.Message> callback)
      Subscribes to a topic.
      Parameters:
      destination - The topic destination.
      callback - The callback for received messages.
      Returns:
      this Stomp instance.
    • 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 Stomp instance.
    • queue

      public Stomp queue(String destination, Callback<Stomp.Message> callback)
      Subscribes to a queue.
      Parameters:
      destination - The queue destination.
      callback - The callback for received messages.
      Returns:
      this Stomp instance.
    • 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 Stomp instance.
    • 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 Stomp instance.
    • ack

      public void ack(Stomp.Message message)
      Acknowledges the receipt of a message.
      Parameters:
      message - The message received from the server.
    • untopic

      public void untopic(String destination)
      Unsubscribes from a topic.
      Parameters:
      destination - The topic destination.
    • unqueue

      public void unqueue(String destination)
      Unsubscribes from a queue.
      Parameters:
      destination - The queue destination.
    • unsubscribe

      public void unsubscribe(String destination)
      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 - true to enable legacy formatting.