Interface PublishService


  • @DoNotImplement
    public interface PublishService
    This service allows extensions to publish new MQTT messages programmatically.
    Since:
    4.0
    • Method Detail

      • publish

        @NotNull java.util.concurrent.CompletableFuture<java.lang.Void> publish​(@NotNull Publish publish)
        Publishes a new MQTT Publish message. The standard MQTT topic matching mechanism of HiveMQ will apply and only subscribed MQTT clients will receive the published message.

        CompletableFuture fails with a RateLimitExceededException if the extension service rate limit was exceeded.

        CompletableFuture fails with a DoNotImplementException if the Publish is implemented by the extension.

        Parameters:
        publish - Object with topic, QoS and message, which should be published to all subscribed clients.
        Returns:
        A CompletableFuture which is complete when the PublishPacket has been processed by HiveMQ.
        Throws:
        java.lang.NullPointerException - If the given publish is null.
        Since:
        4.0.0
      • publishToClient

        @NotNull java.util.concurrent.CompletableFuture<PublishToClientResult> publishToClient​(@NotNull Publish publish,
                                                                                               @NotNull java.lang.String clientId)
        Publishes a new MQTT Publish message to a single client. The PUBLISH will only be delivered to the client with the specified client identifier. This method will not send the publish to the specified client if the client is not subscribed to a topic that matches the topic of the PUBLISH.

        If the client is subscribed to a shared subscription that matches the publish topic, the PUBLISH is still only delivered to the client with the specified client identifier. The retain flag is ignored for the PUBLISH message.

        CompletableFuture fails with a RateLimitExceededException if the extension service rate limit was exceeded.

        CompletableFuture fails with a DoNotImplementException if the Publish is implemented by the extension.

        Parameters:
        publish - Object with topic, QoS and message, which should be published to all subscribed clients.
        clientId - The client to publish to.
        Returns:
        A CompletableFuture which is complete when the PublishPacket has been processed by HiveMQ and contains a PublishToClientResult that is PublishToClientResult.SUCCESSFUL if the client has matching subscriptions or PublishToClientResult.NOT_SUBSCRIBED if it doesn't.
        Throws:
        java.lang.NullPointerException - If the given publish or client id is null.
        java.lang.IllegalArgumentException - If the given client id is empty.
        Since:
        4.0.0