Class PublishPacket.PublishPacketBuilder

  • Enclosing class:
    PublishPacket

    public static final class PublishPacket.PublishPacketBuilder
    extends java.lang.Object
    A class to that allows for the creation of a PublishPacket. Set all of the settings you want in the packet and then use the build() function to get a PublishPacket populated with the settings defined in the builder.
    • Constructor Detail

      • PublishPacketBuilder

        public PublishPacketBuilder()
        Creates a new PublishPacketBuilder so a PublishPacket can be created.
    • Method Detail

      • withPayload

        public PublishPacket.PublishPacketBuilder withPayload​(byte[] payload)
        Sets the payload for the publish message. See MQTT5 Publish Payload
        Parameters:
        payload - The payload for the publish message.
        Returns:
        The PublishPacketBuilder after setting the payload.
      • withQOS

        public PublishPacket.PublishPacketBuilder withQOS​(QOS packetQOS)
        Sets the MQTT quality of service level the message should be delivered with. See MQTT5 QoS
        Parameters:
        packetQOS - The MQTT quality of service level the message should be delivered with.
        Returns:
        The PublishPacketBuilder after setting the QOS.
      • withRetain

        public PublishPacket.PublishPacketBuilder withRetain​(java.lang.Boolean retain)
        Sets if this should be a retained message. Null implies false. See MQTT5 Retain
        Parameters:
        retain - if this is a retained message.
        Returns:
        The PublishPacketBuilder after setting the retain setting.
      • withTopic

        public PublishPacket.PublishPacketBuilder withTopic​(java.lang.String topic)
        Sets the topic this message should be published to. See MQTT5 Topic Name
        Parameters:
        topic - The topic this message should be published to.
        Returns:
        The PublishPacketBuilder after setting the topic.
      • withMessageExpiryIntervalSeconds

        public PublishPacket.PublishPacketBuilder withMessageExpiryIntervalSeconds​(java.lang.Long messageExpiryIntervalSeconds)
        Sets the maximum amount of time allowed to elapse for message delivery before the server should instead delete the message (relative to a recipient). If left null, indicates no expiration timeout. See MQTT5 Message Expiry Interval
        Parameters:
        messageExpiryIntervalSeconds - The maximum amount of time allowed to elapse for message delivery before the server should instead delete the message (relative to a recipient).
        Returns:
        The PublishPacketBuilder after setting the message expiry interval.
      • withTopicAlias

        public PublishPacket.PublishPacketBuilder withTopicAlias​(long topicAlias)
        Sets the topic alias to use when sending this publish. Will only be used if the outbound topic aliasing behavior has been set to Manual. See MQTT5 Topic Alias
        Parameters:
        topicAlias - alias value to use. Must be greater than 0 and less than 65536.
        Returns:
        The PublishPacketBuilder after setting the topic alias.
      • withResponseTopic

        public PublishPacket.PublishPacketBuilder withResponseTopic​(java.lang.String responseTopic)
        Sets the opaque topic string intended to assist with request/response implementations. Not internally meaningful to MQTT5 or this client. See MQTT5 Response Topic
        Parameters:
        responseTopic - Topic string intended to assist with request/response implementations
        Returns:
        The PublishPacketBuilder after setting the response topic.
      • withCorrelationData

        public PublishPacket.PublishPacketBuilder withCorrelationData​(byte[] correlationData)
        Sets the opaque binary data used to correlate between publish messages, as a potential method for request-response implementation. Not internally meaningful to MQTT5. See MQTT5 Correlation Data
        Parameters:
        correlationData - Opaque binary data used to correlate between publish messages
        Returns:
        The PublishPacketBuilder after setting the correlation data.
      • withContentType

        public PublishPacket.PublishPacketBuilder withContentType​(java.lang.String contentType)
        Sets the property specifying the content type of the payload. Not internally meaningful to MQTT5. See MQTT5 Content Type
        Parameters:
        contentType - Property specifying the content type of the payload
        Returns:
        The PublishPacketBuilder after setting the content type.
      • withUserProperties

        public PublishPacket.PublishPacketBuilder withUserProperties​(java.util.List<UserProperty> userProperties)
        Sets the list of MQTT5 user properties included with the packet. See MQTT5 User Property
        Parameters:
        userProperties - List of MQTT5 user properties included with the packet.
        Returns:
        The PublishPacketBuilder after setting the user properties.
      • build

        public PublishPacket build()
        Creates a new PublishPacket using the settings set in the builder.
        Returns:
        The PublishPacket created from the builder