Class MessageHelper


  • public final class MessageHelper
    extends Object
    Utility methods for working with Proton Messages.
    • Field Detail

      • ANNOTATION_X_OPT_RETAIN

        public static final String ANNOTATION_X_OPT_RETAIN
        The name of the AMQP 1.0 message annotation that is used to indicate that the sender of the message intended the message to be retained in the MQTT sense. The value of the property is a boolean. If a message does not contain this annotation, then a consumer must process the message as if the annotation exists and has a value of false.
        See Also:
        Constant Field Values
      • APP_PROPERTY_CACHE_CONTROL

        public static final String APP_PROPERTY_CACHE_CONTROL
        The name of the AMQP 1.0 message application property containing the caching directive to follow for the body of the message.
        See Also:
        Constant Field Values
      • APP_PROPERTY_DEVICE_ID

        public static final String APP_PROPERTY_DEVICE_ID
        The name of the AMQP 1.0 message application property containing the id of the device that has reported the data belongs to.
        See Also:
        Constant Field Values
      • APP_PROPERTY_DEVICE_TTD

        public static final String APP_PROPERTY_DEVICE_TTD
        The name of the AMQP 1.0 message application property containing the time until disconnect of the device that is available for receiving an upstream message for the given number of seconds (short for Time til Disconnect).
        See Also:
        Constant Field Values
      • APP_PROPERTY_GATEWAY_ID

        public static final String APP_PROPERTY_GATEWAY_ID
        The name of the AMQP 1.0 message application property containing the id of the gateway that wants to report data on behalf of another device.
        See Also:
        Constant Field Values
      • APP_PROPERTY_REGISTRATION_STATUS

        public static final String APP_PROPERTY_REGISTRATION_STATUS
        The name of the AMQP 1.0 message application property containing the flag denoting an event sent whenever a device was auto-provisioned.
        See Also:
        Constant Field Values
      • APP_PROPERTY_ADAPTER_INSTANCE_ID

        public static final String APP_PROPERTY_ADAPTER_INSTANCE_ID
        The name of the AMQP 1.0 message application property containing the id of a protocol adapter instance.
        See Also:
        Constant Field Values
      • APP_PROPERTY_LIFESPAN

        public static final String APP_PROPERTY_LIFESPAN
        The name of the AMQP 1.0 message application property containing a lifespan value in seconds.
        See Also:
        Constant Field Values
      • APP_PROPERTY_ORIG_ADDRESS

        public static final String APP_PROPERTY_ORIG_ADDRESS
        The name of the AMQP 1.0 application property that is used to convey the address that a message has been originally published to by a device.
        See Also:
        Constant Field Values
      • APP_PROPERTY_ORIG_ADAPTER

        public static final String APP_PROPERTY_ORIG_ADAPTER
        The name of the AMQP 1.0 message application property containing the name of the protocol adapter over which an uploaded message has originally been received.
        See Also:
        Constant Field Values
      • APP_PROPERTY_QOS

        public static final String APP_PROPERTY_QOS
        The name of the AMQP 1.0 message application property containing the QoS level of the message as set by the device.
        See Also:
        Constant Field Values
      • APP_PROPERTY_REGISTRATION_ASSERTION

        public static final String APP_PROPERTY_REGISTRATION_ASSERTION
        The name of the AMQP 1.0 message application property containing a JWT token asserting a device's registration status.
        See Also:
        Constant Field Values
      • APP_PROPERTY_RESOURCE

        public static final String APP_PROPERTY_RESOURCE
        The name of the AMQP 1.0 message application property containing the resource a message is addressed at.
        See Also:
        Constant Field Values
      • APP_PROPERTY_STATUS

        public static final String APP_PROPERTY_STATUS
        The name of the AMQP 1.0 message application property containing the status code indicating the outcome of processing a request.
        See Also:
        Constant Field Values
      • APP_PROPERTY_TENANT_ID

        public static final String APP_PROPERTY_TENANT_ID
        The name of the AMQP 1.0 message application property containing the id of the tenant the device that has reported the data belongs to.
        See Also:
        Constant Field Values
      • APP_PROPERTY_RESOURCE_VERSION

        public static final String APP_PROPERTY_RESOURCE_VERSION
        The name of the AMQP 1.0 message application property containing the resource version expected by the client.
        See Also:
        Constant Field Values
      • APP_PROPERTY_CMD_VIA

        public static final String APP_PROPERTY_CMD_VIA
        The name of the AMQP 1.0 message application property containing the gateway through which a command is sent.
        See Also:
        Constant Field Values
      • SYS_HEADER_PROPERTY_DELIVERY_COUNT

        public static final String SYS_HEADER_PROPERTY_DELIVERY_COUNT
        The AMQP 1.0 delivery-count message header property.
        See Also:
        Constant Field Values
      • SYS_HEADER_PROPERTY_DURABLE

        public static final String SYS_HEADER_PROPERTY_DURABLE
        The AMQP 1.0 durable message header property.
        See Also:
        Constant Field Values
      • SYS_HEADER_PROPERTY_FIRST_ACQUIRER

        public static final String SYS_HEADER_PROPERTY_FIRST_ACQUIRER
        The AMQP 1.0 first-acquirer message header property.
        See Also:
        Constant Field Values
      • SYS_HEADER_PROPERTY_PRIORITY

        public static final String SYS_HEADER_PROPERTY_PRIORITY
        The AMQP 1.0 priority message header property.
        See Also:
        Constant Field Values
      • SYS_HEADER_PROPERTY_TTL

        public static final String SYS_HEADER_PROPERTY_TTL
        The AMQP 1.0 ttl message header property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_ABSOLUTE_EXPIRY_TIME

        public static final String SYS_PROPERTY_ABSOLUTE_EXPIRY_TIME
        The AMQP 1.0 absolute-expiry-time message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_CONTENT_ENCODING

        public static final String SYS_PROPERTY_CONTENT_ENCODING
        The AMQP 1.0 content-encoding message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_CONTENT_TYPE

        public static final String SYS_PROPERTY_CONTENT_TYPE
        The AMQP 1.0 content-type message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_CORRELATION_ID

        public static final String SYS_PROPERTY_CORRELATION_ID
        The AMQP 1.0 correlation-id message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_CREATION_TIME

        public static final String SYS_PROPERTY_CREATION_TIME
        The AMQP 1.0 creation-time message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_GROUP_ID

        public static final String SYS_PROPERTY_GROUP_ID
        The AMQP 1.0 group-id message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_GROUP_SEQUENCE

        public static final String SYS_PROPERTY_GROUP_SEQUENCE
        The AMQP 1.0 group-sequence message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_MESSAGE_ID

        public static final String SYS_PROPERTY_MESSAGE_ID
        The AMQP 1.0 message-id message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_REPLY_TO

        public static final String SYS_PROPERTY_REPLY_TO
        The AMQP 1.0 reply-to message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_REPLY_TO_GROUP_ID

        public static final String SYS_PROPERTY_REPLY_TO_GROUP_ID
        The AMQP 1.0 reply-to-group-id message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_SUBJECT

        public static final String SYS_PROPERTY_SUBJECT
        The AMQP 1.0 subject message property.
        See Also:
        Constant Field Values
      • SYS_PROPERTY_USER_ID

        public static final String SYS_PROPERTY_USER_ID
        The AMQP 1.0 user-id message property.
        See Also:
        Constant Field Values
      • TTD_VALUE_UNLIMITED

        public static final int TTD_VALUE_UNLIMITED
        The time-til-disconnect value to use for indicating that a device will remain connected until further notice.
        See Also:
        Constant Field Values
      • JMS_VENDOR_PROPERTY_CONTENT_ENCODING

        public static final String JMS_VENDOR_PROPERTY_CONTENT_ENCODING
        The JMS_AMQP_CONTENT_ENCODING vendor property name.
        See Also:
        Constant Field Values
      • JMS_VENDOR_PROPERTY_CONTENT_TYPE

        public static final String JMS_VENDOR_PROPERTY_CONTENT_TYPE
        The JMS_AMQP_CONTENT_TYPE vendor property name.
        See Also:
        Constant Field Values
      • CONTENT_TYPE_APPLICATION_JSON

        public static final String CONTENT_TYPE_APPLICATION_JSON
        The MIME type representing the String representation of a JSON Object.
        See Also:
        Constant Field Values
      • CONTENT_TYPE_OCTET_STREAM

        public static final String CONTENT_TYPE_OCTET_STREAM
        The MIME type representing an opaque array of bytes.
        See Also:
        Constant Field Values
      • CONTENT_TYPE_TEXT_PLAIN

        public static final String CONTENT_TYPE_TEXT_PLAIN
        The MIME type representing plain text.
        See Also:
        Constant Field Values
    • Method Detail

      • getDeviceId

        public static String getDeviceId​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_DEVICE_ID application property.
        Parameters:
        msg - The message.
        Returns:
        The property value or null if not set.
        Throws:
        NullPointerException - if message is null.
      • getDeviceId

        public static String getDeviceId​(org.apache.qpid.proton.amqp.messaging.ApplicationProperties properties)
        Gets the value of a message's APP_PROPERTY_DEVICE_ID application property.
        Parameters:
        properties - The message's application properties.
        Returns:
        The property value or null if not set.
      • getTenantId

        public static String getTenantId​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_TENANT_ID application property.
        Parameters:
        msg - The message.
        Returns:
        The property value or null if not set.
        Throws:
        NullPointerException - if message is null.
      • getTenantId

        public static String getTenantId​(org.apache.qpid.proton.amqp.messaging.ApplicationProperties properties)
        Gets the value of a message's APP_PROPERTY_TENANT_ID application property.
        Parameters:
        properties - The message's application properties.
        Returns:
        The property value or null if not set.
      • getGatewayId

        public static String getGatewayId​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_GATEWAY_ID application property.
        Parameters:
        msg - The message.
        Returns:
        The property value or null if not set.
        Throws:
        NullPointerException - if message is null.
      • getGatewayId

        public static String getGatewayId​(org.apache.qpid.proton.amqp.messaging.ApplicationProperties properties)
        Gets the value of a message's APP_PROPERTY_GATEWAY_ID application property.
        Parameters:
        properties - The message's application properties.
        Returns:
        The property value or null if not set.
      • getRegistrationStatus

        public static String getRegistrationStatus​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_REGISTRATION_STATUS application property.
        Parameters:
        msg - The message.
        Returns:
        The property value or null if not set.
        Throws:
        NullPointerException - if message is null.
      • getQoS

        public static Integer getQoS​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_QOS application property.
        Parameters:
        msg - The message.
        Returns:
        The property value or null if not set.
        Throws:
        NullPointerException - if message is null.
      • getRegistrationAssertion

        public static String getRegistrationAssertion​(org.apache.qpid.proton.message.Message msg)
        Gets the registration assertion conveyed in an AMQP 1.0 message.

        The assertion is expected to be contained in the message's application-properties under key APP_PROPERTY_REGISTRATION_ASSERTION.

        Parameters:
        msg - The message.
        Returns:
        The assertion or null if the message does not contain an assertion (at the expected location).
      • getAndRemoveRegistrationAssertion

        public static String getAndRemoveRegistrationAssertion​(org.apache.qpid.proton.message.Message msg)
        Gets and removes the registration assertion conveyed in an AMQP 1.0 message.

        The assertion is expected to be contained in the message's application-properties under key APP_PROPERTY_REGISTRATION_ASSERTION.

        Parameters:
        msg - The message.
        Returns:
        The assertion or null if the message does not contain an assertion (at the expected location).
      • getDeviceIdAnnotation

        public static String getDeviceIdAnnotation​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_DEVICE_ID annotation.
        Parameters:
        msg - The message.
        Returns:
        The annotation value or null if not set.
      • getTenantIdAnnotation

        public static String getTenantIdAnnotation​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_TENANT_ID annotation.
        Parameters:
        msg - The message.
        Returns:
        The annotation value or null if not set.
      • getApplicationProperty

        public static <T> T getApplicationProperty​(org.apache.qpid.proton.amqp.messaging.ApplicationProperties props,
                                                   String name,
                                                   Class<T> type)
        Gets the value of a specific application property.
        Type Parameters:
        T - The expected type of the property to retrieve the value of.
        Parameters:
        props - The application properties to retrieve the value from.
        name - The property name.
        type - The expected value type.
        Returns:
        The value or null if the properties do not contain a value of the expected type for the given name.
      • getJsonPayload

        public static io.vertx.core.json.JsonObject getJsonPayload​(org.apache.qpid.proton.message.Message msg)
        Parses a message's body into a JSON object.
        Parameters:
        msg - The AMQP 1.0 message to parse the body of.
        Returns:
        The message body parsed into a JSON object or null if the message does not have a Data nor an AmqpValue section or if the body section is empty.
        Throws:
        NullPointerException - if the message is null.
        io.vertx.core.json.DecodeException - if the payload cannot be parsed into a JSON object.
      • getPayload

        public static io.vertx.core.buffer.Buffer getPayload​(org.apache.qpid.proton.message.Message msg)
        Gets the payload data contained in a message's body.

        The bytes in the returned buffer are determined as follows:

        • If the body is a Data section, the bytes contained in the Data section are returned.
        • If the body is an AmqpValue section and contains a byte array, the bytes in the array are returned.
        • If the body is an AmqpValue section and contains a String, the String's UTF-8 encoding is returned.
        • In all other cases, null is returned.
        Parameters:
        msg - The AMQP 1.0 message to parse the body of.
        Returns:
        The bytes representing the payload or null if the message neither has a Data nor AmqpValue section or if a contained AmqpValue section doesn't have a String or byte array value.
        Throws:
        NullPointerException - if the message is null.
      • getPayloadAsString

        public static String getPayloadAsString​(org.apache.qpid.proton.message.Message msg)
        Gets the payload data contained in a message's body as a String.

        The String returned is created as follows:

        • If the body is a Data section, the String is created by interpreting the bytes as UTF-8 encoded characters.
        • If the body is an AmqpValue section and contains a byte array, the String is created by interpreting the bytes as UTF-8 encoded characters.
        • If the body is an AmqpValue section and contains a String, the String is returned as is.
        • In all other cases, null is returned.
        Parameters:
        msg - The AMQP 1.0 message to parse the body of.
        Returns:
        The String representation of the payload data or null if the type or value type of the message body section isn't supported.
        Throws:
        NullPointerException - if the message is null.
      • getPayloadSize

        public static int getPayloadSize​(org.apache.qpid.proton.message.Message msg)
        Gets the size of the payload data contained in a message's body.

        If there is no body section or if its type is unsupported, 0 is returned.

        Parameters:
        msg - The AMQP 1.0 message to parse the body of.
        Returns:
        The payload size in bytes, 0 if message body is null or unsupported.
        Throws:
        NullPointerException - if the message is null.
      • addTenantId

        public static void addTenantId​(org.apache.qpid.proton.message.Message msg,
                                       String tenantId)
        Adds a tenant ID to a message's application properties.

        The name of the application property is APP_PROPERTY_TENANT_ID.

        Parameters:
        msg - The message.
        tenantId - The tenant identifier to add.
        Throws:
        NullPointerException - if any of the parameters are null.
      • addDeviceId

        public static void addDeviceId​(org.apache.qpid.proton.message.Message msg,
                                       String deviceId)
        Adds a device ID to a message's application properties.

        The name of the application property is APP_PROPERTY_DEVICE_ID.

        Parameters:
        msg - The message.
        deviceId - The device identifier to add.
        Throws:
        NullPointerException - if any of the parameters are null.
      • addRegistrationAssertion

        public static void addRegistrationAssertion​(org.apache.qpid.proton.message.Message msg,
                                                    String token)
        Adds a registration assertion to an AMQP 1.0 message.

        The assertion is put to the message's application-properties under key APP_PROPERTY_REGISTRATION_ASSERTION.

        Parameters:
        msg - The message.
        token - The assertion to add.
        Throws:
        NullPointerException - if any of the parameters are null.
      • addCacheDirective

        public static void addCacheDirective​(org.apache.qpid.proton.message.Message msg,
                                             CacheDirective cacheDirective)
        Adds a caching directive to an AMQP 1.0 message.

        The directive is put to the message's application-properties under key APP_PROPERTY_CACHE_CONTROL.

        Parameters:
        msg - The message to add the directive to.
        cacheDirective - The cache directive.
        Throws:
        NullPointerException - if any of the parameters are null.
      • getCacheDirective

        public static String getCacheDirective​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_CACHE_CONTROL application property.
        Parameters:
        msg - The message to get the property from.
        Returns:
        The property value or null if not set.
      • setTimeToLive

        public static void setTimeToLive​(org.apache.qpid.proton.message.Message message,
                                         Duration timeToLive)
        Sets the time-to-live for the given AMQP 1.0 message.
        Parameters:
        message - The message whose time-to-live is to be set.
        timeToLive - The time-to-live duration to be set on the message.
        Throws:
        NullPointerException - if any of the parameters is null.
      • addTimeUntilDisconnect

        public static void addTimeUntilDisconnect​(org.apache.qpid.proton.message.Message msg,
                                                  int timeUntilDisconnect)
        Adds a property indicating a device's time until disconnect property to an AMQP 1.0 message.

        The value is put to the message's application-properties under key APP_PROPERTY_DEVICE_TTD.

        Parameters:
        msg - The message to add the property to.
        timeUntilDisconnect - The value of the property (number of seconds).
      • getTimeUntilDisconnect

        public static Integer getTimeUntilDisconnect​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_DEVICE_TTD application property.
        Parameters:
        msg - The message to get the property from.
        Returns:
        The property value or null if not set.
      • getStatus

        public static Integer getStatus​(org.apache.qpid.proton.message.Message msg)
        Gets the value of a message's APP_PROPERTY_STATUS application property.
        Parameters:
        msg - The message to get the property from.
        Returns:
        The property value or null if not set.
      • addStatus

        public static void addStatus​(org.apache.qpid.proton.message.Message msg,
                                     int status)
        Adds a property indicating the outcome of an operation to a (response) message.

        The value will be stored in the message's APP_PROPERTY_STATUS application property.

        Parameters:
        msg - The message to add the status to.
        status - The status to set.
        Throws:
        NullPointerException - if any of the parameters are null.
      • addProperty

        public static void addProperty​(org.apache.qpid.proton.message.Message msg,
                                       String key,
                                       Object value)
        Adds a property to an AMQP 1.0 message.

        The property is added to the message's application-properties.

        Parameters:
        msg - The message.
        key - The property key.
        value - The property value.
        Throws:
        NullPointerException - if any of the parameters are null.
      • rejected

        public static void rejected​(io.vertx.proton.ProtonDelivery delivery,
                                    org.apache.qpid.proton.amqp.transport.ErrorCondition error)
        Rejects and settles an AMQP 1.0 message.
        Parameters:
        delivery - The message's delivery handle.
        error - The error condition to set as the reason for rejecting the message (may be null.
        Throws:
        NullPointerException - if delivery is null.
      • annotate

        public static void annotate​(org.apache.qpid.proton.message.Message msg,
                                    ResourceIdentifier resourceIdentifier)
        Adds several AMQP 1.0 message annotations to the given message that are used to process/route the message.

        In particular, the following annotations are added:

        Parameters:
        msg - the message to add the message annotations to.
        resourceIdentifier - the resource identifier that will be added as annotation.
      • addJmsVendorProperties

        public static void addJmsVendorProperties​(org.apache.qpid.proton.message.Message msg)
        Adds JMS vendor properties defined by AMQP JMS Mapping 1.0 as AMQP 1.0 application properties to a given message.

        The following vendor properties are added (if the message has a corresponding non-null value set):

        Parameters:
        msg - the message to add the vendor properties to.
      • addAnnotation

        public static void addAnnotation​(org.apache.qpid.proton.message.Message msg,
                                         String key,
                                         Object value)
        Adds a value for a symbol to an AMQP 1.0 message's annotations.
        Parameters:
        msg - the message to add the symbol to.
        key - the name of the symbol to add a value for.
        value - the value to add.
      • getAnnotation

        public static <T> T getAnnotation​(org.apache.qpid.proton.message.Message msg,
                                          String key,
                                          Class<T> type)
        Returns the value to which the specified key is mapped in the message annotations, or null if the message annotations contain no mapping for the key.
        Type Parameters:
        T - the expected type of the property to read.
        Parameters:
        msg - the message that contains the annotations.
        key - the name of the symbol to return a value for.
        type - the expected type of the value.
        Returns:
        the annotation's value or null if no such annotation exists or its value is not of the expected type.
      • setCreationTime

        public static void setCreationTime​(org.apache.qpid.proton.message.Message msg)
        Sets the creation-time of an AMQP 1.0 message to the current point in time.

        This method does nothing if the message already has a creation time (> 0) set.

        Parameters:
        msg - The message to set the property on.
      • isDeviceCurrentlyConnected

        public static boolean isDeviceCurrentlyConnected​(org.apache.qpid.proton.message.Message msg)
        Checks if a device is currently connected to a protocol adapter.

        If this method returns true an attempt could be made to send a command to the device.

        This method uses the message's creation time and TTD value to determine the point in time until which the device will remain connected.

        Parameters:
        msg - The message that is checked for a TTD value.
        Returns:
        true if the TTD value contained in the message indicates that the device will stay connected for some additional time.
        Throws:
        NullPointerException - If msg is null.
      • setJsonPayload

        public static void setJsonPayload​(org.apache.qpid.proton.message.Message message,
                                          io.vertx.core.json.JsonObject payload)
        Sets the payload of an AMQP message using a Data section.

        The message's content-type will be set to CONTENT_TYPE_APPLICATION_JSON. The message's Data section will contain the UTF-8 encoding of the given JSON object.

        Parameters:
        message - The message.
        payload - The payload or null if there is no payload to convey in the message body.
        Throws:
        NullPointerException - If message is null.
      • setJsonPayload

        public static void setJsonPayload​(org.apache.qpid.proton.message.Message message,
                                          String payload)
        Sets the payload of an AMQP message using a Data section.

        The message's content-type will be set to CONTENT_TYPE_APPLICATION_JSON. The message's Data section will contain the UTF-8 encoding of the given payload. Note: No formal check is done if the payload actually is a JSON string.

        Parameters:
        message - The message.
        payload - The payload or null if there is no payload to convey in the message body.
        Throws:
        NullPointerException - If message is null.
      • setPayload

        public static void setPayload​(org.apache.qpid.proton.message.Message message,
                                      String contentType,
                                      io.vertx.core.buffer.Buffer payload)
        Sets the payload of an AMQP message using a Data section.
        Parameters:
        message - The message.
        contentType - The type of the payload. A non-null type value will be used to set the content-type property of the message, if the payload is either not null or the empty notification type is given. If the given type is null and the payload is not null, the default content type will be used.
        payload - The payload or null if there is no payload to convey in the message body.
        Throws:
        NullPointerException - If message is null.
      • setPayload

        public static void setPayload​(org.apache.qpid.proton.message.Message message,
                                      String contentType,
                                      byte[] payload)
        Sets the payload of an AMQP message using a Data section.
        Parameters:
        message - The message.
        contentType - The type of the payload. A non-null type value will be used to set the content-type property of the message, if the payload is either not null or the empty notification type is given. If the given type is null and the payload is not null, the default content type will be used.
        payload - The payload or null if there is no payload to convey in the message body.
        Throws:
        NullPointerException - If message is null.
      • hasDataBody

        public static boolean hasDataBody​(org.apache.qpid.proton.message.Message message)
        Checks if a message's body consists of an AMQP Data section.
        Parameters:
        message - The message to check.
        Returns:
        true if the body consists of a Data section, false otherwise.
        Throws:
        NullPointerException - If message is null.
      • hasAmqpValueBody

        public static boolean hasAmqpValueBody​(org.apache.qpid.proton.message.Message message)
        Checks if a message's body consists of an AMQP AmqpValue section.
        Parameters:
        message - The message to check.
        Returns:
        true if the body consists of an AmqpValue section, false otherwise.
        Throws:
        NullPointerException - If message is null.
      • getShallowCopy

        public static org.apache.qpid.proton.message.Message getShallowCopy​(org.apache.qpid.proton.message.Message message)
        Returns a copy of the given message.

        This is a shallow copy of the Message object, except for the copied Properties.

        Parameters:
        message - The message to copy.
        Returns:
        The message copy.
      • getCorrelationId

        public static Object getCorrelationId​(org.apache.qpid.proton.message.Message message)
        Gets the identifier to use for correlating to a given message.
        Parameters:
        message - The message to correlate to.
        Returns:
        The value of the message's correlation-id property, if not null. Otherwise, the value of the message-id property or null if neither the message nor the correlation ID properties are set.
      • newMessage

        @Deprecated
        public static org.apache.qpid.proton.message.Message newMessage​(QoS qos,
                                                                        ResourceIdentifier target,
                                                                        String publishAddress,
                                                                        String contentType,
                                                                        io.vertx.core.buffer.Buffer payload,
                                                                        TenantObject tenant,
                                                                        io.vertx.core.json.JsonObject deviceDefaultProperties,
                                                                        Integer timeUntilDisconnect,
                                                                        Duration timeToLive,
                                                                        String adapterTypeName,
                                                                        boolean addDefaults,
                                                                        boolean addJmsVendorProps)
        Creates a new AMQP 1.0 message.

        This method creates a new Message and sets

        • its creation-time to the current system time,
        • its content-type to the given value,
        • its payload as an AMQP Data section
        The message is then passed to addProperties(Message, QoS, ResourceIdentifier, String, TenantObject, JsonObject, Integer, Duration, String, boolean, boolean).
        Parameters:
        qos - The QoS level with which the device sent the message to the protocol adapter or null if the corresponding qos application property in the AMQP message should not be set.
        target - The target address of the message. The target address is used to determine if the message represents an event or not.
        publishAddress - The address that the message has been published to originally by the device or null if unknown.

        This address will be transport protocol specific, e.g. an HTTP based adapter will probably use URIs here whereas an MQTT based adapter might use the MQTT message's topic.

        contentType - The content type describing the message's payload or null if no content type should be set.
        payload - The message payload or null if the message has no payload.
        tenant - The information registered for the tenant that the device belongs to or null if no information about the tenant is available.
        deviceDefaultProperties - The device's default properties registered at the device level or null if no default properties are registered for the device.
        timeUntilDisconnect - The number of seconds until the device that has published the message will disconnect from the protocol adapter or null if unknown.
        timeToLive - The message's time-to-live as provided by the device or null if the device did not provide any TTL.
        adapterTypeName - The type name of the protocol adapter that the message has been published to.
        addDefaults - true if the default properties registered for the device should be added to the message. The properties to add are determined by merging the properties returned by TenantObject.getDefaults() with the given device level default properties.
        addJmsVendorProps - true if JMS Vendor Properties should be added to the message.
        Returns:
        The newly created message.
        Throws:
        NullPointerException - if target or adapterTypeName is null.
      • newMessage

        public static org.apache.qpid.proton.message.Message newMessage​(ResourceIdentifier target,
                                                                        String contentType,
                                                                        io.vertx.core.buffer.Buffer payload,
                                                                        TenantObject tenant,
                                                                        Map<String,​Object> properties,
                                                                        Map<String,​Object> deviceDefaultProperties,
                                                                        boolean addDefaults,
                                                                        boolean addJmsVendorProps)
        Creates a new AMQP 1.0 message.

        This method creates a new Message and sets

        • its creation-time to the current system time,
        • its content-type to the given value,
        • its payload as an AMQP Data section
        The message is then passed to addProperties(Message, ResourceIdentifier, TenantObject, Map, Map, boolean, boolean).
        Parameters:
        target - The target address of the message. The target address is used to determine if the message represents an event or not.
        contentType - The content type describing the message's payload. If null, the message's content-type property will either be derived from the given properties or deviceDefaultProperties (if set there) or it will be set to the default content type if the given payload isn't null.
        payload - The message payload or null if the message has no payload.
        tenant - The information registered for the tenant that the device belongs to or null if no information about the tenant is available.
        properties - Additional message properties or null if the message has no additional properties.
        deviceDefaultProperties - The device's default properties registered at the device level or null if no default properties are registered for the device.
        addDefaults - true if the default properties registered for the device should be added to the message. The properties to add are determined by merging the properties returned by TenantObject.getDefaults() with the given device level default properties.
        addJmsVendorProps - true if JMS Vendor Properties should be added to the message.
        Returns:
        The newly created message.
        Throws:
        NullPointerException - if target is null.
      • addProperties

        @Deprecated
        public static org.apache.qpid.proton.message.Message addProperties​(org.apache.qpid.proton.message.Message msg,
                                                                           QoS qos,
                                                                           ResourceIdentifier target,
                                                                           String publishAddress,
                                                                           TenantObject tenant,
                                                                           io.vertx.core.json.JsonObject deviceDefaultProperties,
                                                                           Integer timeUntilDisconnect,
                                                                           Duration timeToLive,
                                                                           String adapterTypeName,
                                                                           boolean addDefaults,
                                                                           boolean addJmsVendorProps)
        Sets Hono specific properties on an AMQP 1.0 message.

        The following properties are set:

        • to will be set to the address consisting of the target's endpoint and tenant
        • creation-time will be set to the current number of milliseconds since 1970-01-01T00:00:00Z if not set already
        • application property device_id will be set to the target's resourceId property
        • application property orig_address will be set to the given publish address
        • application property orig_adapter will be set to the given adapter type name}
        • application property ttd will be set to the given time-til-disconnect
        In addition, this method
        • optionally augments the message with missing (application) properties corresponding to the default properties registered at the tenant and device level. Default properties defined at the device level take precedence over properties with the same name defined at the tenant level.
        • optionally adds JMS vendor properties.
        • sets the message's content-type to the fall back content type, if the default properties do not contain a content type and the message has no content type set yet.
        • sets the message's ttl header field based on the (device provided) time-to-live duration as specified by the Tenant API.
        Parameters:
        msg - The message to add the properties to.
        qos - The QoS level with which the device sent the message to the protocol adapter or null if the corresponding qos application property in the AMQP message should not be set.
        target - The target address of the message or null if the message's to property contains the target address. The target address is used to determine if the message represents an event or not. Determining this information from the to property requires additional parsing which can be prevented by passing in the target address as a ResourceIdentifier instead.
        publishAddress - The address that the message has been published to originally by the device or null if unknown.

        This address will be transport protocol specific, e.g. an HTTP based adapter will probably use URIs here whereas an MQTT based adapter might use the MQTT message's topic.

        tenant - The information registered for the tenant that the device belongs to or null if no information about the tenant is available.
        deviceDefaultProperties - The device's default properties registered at the device level or null if no default properties are registered for the device.
        timeUntilDisconnect - The number of seconds until the device that has published the message will disconnect from the protocol adapter or null if unknown.
        timeToLive - The message's time-to-live as provided by the device or null if the device did not provide any TTL.
        adapterTypeName - The type name of the protocol adapter that the message has been published to.
        addDefaults - true if the default properties registered for the device should be added to the message. The properties to add are determined by merging the properties returned by TenantObject.getDefaults() with the given device level default properties.
        addJmsVendorProps - true if JMS Vendor Properties should be added to the message.
        Returns:
        The message with its properties set.
        Throws:
        NullPointerException - if message or adapterTypeName are null.
        IllegalArgumentException - if target is null and the message does not have an address set.
      • addProperties

        public static org.apache.qpid.proton.message.Message addProperties​(org.apache.qpid.proton.message.Message message,
                                                                           ResourceIdentifier target,
                                                                           TenantObject tenant,
                                                                           Map<String,​Object> properties,
                                                                           Map<String,​Object> deviceDefaultProperties,
                                                                           boolean addDefaults,
                                                                           boolean addJmsVendorProps)
        Sets Hono specific properties on an AMQP 1.0 message.

        The following properties are set:

        • to will be set to the address consisting of the target's endpoint and tenant
        • creation-time will be set to the current number of milliseconds since 1970-01-01T00:00:00Z if not set already
        • application property device_id will be set to the target's resourceId property
        In addition, this method
        • augments the message with the given properties.
        • optionally augments the message with missing (application) properties corresponding to the default properties registered at the tenant and device level. Default properties defined at the device level take precedence over properties with the same name defined at the tenant level.
        • optionally adds JMS vendor properties.
        • sets the message's content-type to the fall back content type, if the properties or deviceDefaultProperties do not contain a content type property, the message has no content type set yet and the payload of the message is not null.
        • sets the message's ttl header field based on the (device provided) time-to-live duration as specified by the Tenant API.
        Parameters:
        message - The message to add the properties to.
        target - The target address of the message or null if the message's to property contains the target address. The target address is used to determine if the message represents an event or not. Determining this information from the to property requires additional parsing which can be prevented by passing in the target address as a ResourceIdentifier instead.
        tenant - The information registered for the tenant that the device belongs to or null if no information about the tenant is available.
        properties - Additional message properties or null if the message has no additional properties.
        deviceDefaultProperties - The device's default properties registered at the device level or null if no default properties are registered for the device.
        addDefaults - true if the default properties registered for the device should be added to the message. The properties to add are determined by merging the properties returned by TenantObject.getDefaults() with the given device level default properties.
        addJmsVendorProps - true if JMS Vendor Properties should be added to the message.
        Returns:
        The message with its properties set.
        Throws:
        NullPointerException - if message is null.
        IllegalArgumentException - if target is null and the message does not have an address set.
      • addDefaults

        public static org.apache.qpid.proton.message.Message addDefaults​(org.apache.qpid.proton.message.Message message,
                                                                         ResourceIdentifier target,
                                                                         Map<String,​Object> defaults,
                                                                         long maxTtl)
        Adds default properties to an AMQP message.

        This method also sets the message's time-to-live (TTL) property as described in

        Parameters:
        message - The message to add the properties to.
        target - The target address of the message or null if the message's to property contains the target address. The target address is used to determine if the message represents an event or not. Determining this information from the to property requires additional parsing which can be prevented by passing in the target address as a ResourceIdentifier instead.
        defaults - The default properties (device and tenant level) to set or null if no default properties are defined for the device that the message originates from.
        maxTtl - The maximum time-to-live (in seconds) that should be used for limiting a default TTL.
        Returns:
        The message with the default properties set.
        Throws:
        NullPointerException - if message is null.
        IllegalArgumentException - if target is null and the message does not have an address set.