Class StompClientBuilder

java.lang.Object
org.schlunzis.zis.stomp.client.StompClientBuilder

public final class StompClientBuilder extends Object
Builder for StompClient instances.
Since:
1.0.0
See Also:
  • Method Details

    • endpoint

      public StompClientBuilder endpoint(URI endpoint)

      Sets the STOMP endpoint URI. This parameter is required.

      The protocol must be either ws or wss. Example: ws://localhost:8080/ws

      Parameters:
      endpoint - the STOMP endpoint URI
      Returns:
      the builder instance
      Since:
      1.0.0
    • messageConverter

      public StompClientBuilder messageConverter(MessageConverter messageConverter)

      Sets the message converter to be used by the client. If not set, the builder will attempt to create a suitable MessageConverter automatically.

      It will first look for a Jackson 3 ObjectMapper, then for a Jackson 2 ObjectMapper. If one of them is found, a corresponding MessageConverter will be created. If none is found, a StringMessageConverter will be used.

      Parameters:
      messageConverter - the message converter
      Returns:
      the builder instance
      Since:
      1.0.0
    • onError

      public StompClientBuilder onError(OnErrorConsumer onErrorConsumer)

      Sets the consumer to run when a STOMP ERROR frame is received. If an ERROR frame is received from the server, the provided consumer will be invoked with the error details.

      If this happens, the server closes the connection, since ERROR frames are only sent in fatal error situations like protocol violations. If you think this is a problem with the client, please open an issue on GitHub.

      If you want to recover from such errors, you need to build a new StompClient instance and connect again. However, be aware that this is not recommended, since ERROR frames usually indicate serious problems. You can reuse the same builder instance to build a new client with the same configuration.

      The builder and the constructed StompClient will hold a strong reference to the provided consumer even after the client is closed.

      Parameters:
      onErrorConsumer - the error consumer
      Returns:
      the builder instance
      Since:
      1.0.0
    • receiptTimeout

      public StompClientBuilder receiptTimeout(Duration receiptTimeout)
      Sets the receipt timeout duration. If a receipt is requested, this timeout defines how long the client will wait for the receipt frame from the server before considering it a failure. The default is 10 seconds.
      Parameters:
      receiptTimeout - the receipt timeout duration
      Returns:
      the builder instance
      Since:
      1.0.0
    • receiptPolicy

      public StompClientBuilder receiptPolicy(ReceiptPolicy receiptPolicy)
      Sets the receipt policy for the client. The receipt policy defines for which operations the client will request receipts from the server. By default, no receipts are requested.
      Parameters:
      receiptPolicy - the receipt policy
      Returns:
      the builder instance
      Since:
      1.0.0
    • build

      public StompClient build() throws IllegalStateException

      Builds the StompClient instance.

      You may call this method multiple times to create multiple clients with the same configuration.

      Returns:
      the STOMP client
      Throws:
      IllegalStateException - if the endpoint is not set
      Since:
      1.0.0