Message Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.device.Message

public class Message

Field Summary

Modifier and Type Field and Description
final Charset DEFAULT_IOTHUB_MESSAGE_CHARSET

Constructor Summary

Constructor Description
Message()

Constructor.

Message(byte[] body)

Constructor.

Message(String body)

Constructor.

Method Summary

Modifier and Type Method and Description
ByteArrayOutputStream getBodyStream()

The stream content of the body.

byte [] getBytes()

The byte content of the body.

String getConnectionDeviceId()
String getConnectionModuleId()
String getContentEncoding()

Returns this message's content encoding. This value is null by default

String getContentType()

Return the message's content type. This value is null by default

CorrelatingMessageCallback getCorrelatingMessageCallback()
Object getCorrelatingMessageCallbackContext()
String getCorrelationId()

Getter for the correlationId property

Date getCreationTimeUTC()
String getCreationTimeUTCString()

Returns the iot hub accepted format for the creation time utc

ex: oct 1st, 2018 yields 2008-10-01T17:04:32.0000000

String getDeliveryAcknowledgement()

Getter for the delivery acknowledgement system property

String getInputName()
IotHubConnectionString getIotHubConnectionString()

Getter for the iotHubConnectionString property

String getMessageId()

Getter for the messageId property

MessageType getMessageType()

Getter for the Message type

String getOutputName()
MessageProperty [] getProperties()

Returns a copy of the message properties.

String getProperty(String name)

Gets the values of user-defined properties of this Message.

String getTo()

Getter for the To system property

String getUserId()

Getter for the User ID system property

boolean isExpired()

Verifies whether the message is expired or not

boolean isSecurityMessage()
void setAbsoluteExpiryTime(long absoluteTimeout)

Setter for the expiryTime property using absolute time

void setAsSecurityMessage()
void setConnectionDeviceId(String connectionDeviceId)
void setConnectionModuleId(String connectionModuleId)
void setContentEncoding(String contentEncoding)

Set the content encoding of this message. Used in message routing.

final void setContentType(String contentType)

Set the content type of this message. Used in message routing.

void setCorrelatingMessageCallback(CorrelatingMessageCallback correlatingMessageCallback)
void setCorrelatingMessageCallbackContext(Object correlatingMessageCallbackContext)
void setCorrelationId(String correlationId)

Setter for the correlationId property

final void setCreationTimeUTC(Date creationTimeUTC)
void setExpiryTime(long timeOut)

Setter for the expiryTime property. This setter uses relative time, not absolute time.

void setInputName(String inputName)

Set the input name of the message, used in routing for module communications

void setIotHubConnectionString(IotHubConnectionString iotHubConnectionString)

Setter for the iotHubConnectionString type

void setMessageId(String messageId)

Setter for the messageId property

void setMessageType(MessageType type)

Setter for the Message type

void setOutputName(String outputName)

Set the output channel name to send to. Used in routing for module communications

void setProperty(String name, String value)

Adds or sets user-defined properties of this Message.

void setUserId(String userId)
String toString()

Field Details

DEFAULT_IOTHUB_MESSAGE_CHARSET

public static final Charset DEFAULT_IOTHUB_MESSAGE_CHARSET= StandardCharsets.UTF_8

Constructor Details

Message

public Message()

Constructor.

Message

public Message(byte[] body)

Constructor.

Parameters:

body - The body of the new Message instance.

Message

public Message(String body)

Constructor.

Parameters:

body - The body of the new Message instance. It is internally serialized to a byte array using UTF-8 encoding.

Method Details

getBodyStream

public ByteArrayOutputStream getBodyStream()

The stream content of the body.

Returns:

always returns null.

getBytes

public byte [] getBytes()

The byte content of the body.

Returns:

A copy of this Message body, as a byte array.

getConnectionDeviceId

public String getConnectionDeviceId()

getConnectionModuleId

public String getConnectionModuleId()

getContentEncoding

public String getContentEncoding()

Returns this message's content encoding. This value is null by default

Returns:

the message's content encoding.

getContentType

public String getContentType()

Return the message's content type. This value is null by default

Returns:

the message's content type

getCorrelatingMessageCallback

public CorrelatingMessageCallback getCorrelatingMessageCallback()

getCorrelatingMessageCallbackContext

public Object getCorrelatingMessageCallbackContext()

getCorrelationId

public String getCorrelationId()

Getter for the correlationId property

Returns:

The property value

getCreationTimeUTC

public Date getCreationTimeUTC()

getCreationTimeUTCString

public String getCreationTimeUTCString()

Returns the iot hub accepted format for the creation time utc

ex: oct 1st, 2018 yields 2008-10-01T17:04:32.0000000

Returns:

the iot hub accepted format for the creation time utc

getDeliveryAcknowledgement

public String getDeliveryAcknowledgement()

Getter for the delivery acknowledgement system property

Returns:

the delivery acknowledgement value

getInputName

public String getInputName()

getIotHubConnectionString

public IotHubConnectionString getIotHubConnectionString()

Getter for the iotHubConnectionString property

Returns:

the iotHubConnectionString value

getMessageId

public String getMessageId()

Getter for the messageId property

Returns:

The property value

getMessageType

public MessageType getMessageType()

Getter for the Message type

Returns:

the Message type value

getOutputName

public String getOutputName()

getProperties

public MessageProperty [] getProperties()

Returns a copy of the message properties.

Returns:

a copy of the message properties.

getProperty

public String getProperty(String name)

Gets the values of user-defined properties of this Message.

Parameters:

name - Name of the user-defined property to search for.

Returns:

The value of the property if it is set, or null otherwise.

getTo

public String getTo()

Getter for the To system property

Returns:

the To value

getUserId

public String getUserId()

Getter for the User ID system property

Returns:

the User ID value

isExpired

public boolean isExpired()

Verifies whether the message is expired or not

Returns:

true if the message is expired, false otherwise

isSecurityMessage

public boolean isSecurityMessage()

setAbsoluteExpiryTime

public void setAbsoluteExpiryTime(long absoluteTimeout)

Setter for the expiryTime property using absolute time

Parameters:

absoluteTimeout - The time out for the message, in milliseconds.

setAsSecurityMessage

public void setAsSecurityMessage()

setConnectionDeviceId

public void setConnectionDeviceId(String connectionDeviceId)

Parameters:

connectionDeviceId

setConnectionModuleId

public void setConnectionModuleId(String connectionModuleId)

Parameters:

connectionModuleId

setContentEncoding

public void setContentEncoding(String contentEncoding)

Set the content encoding of this message. Used in message routing.

Parameters:

contentEncoding - the content encoding of the message. May be null if you don't want to specify a content encoding.

setContentType

public final void setContentType(String contentType)

Set the content type of this message. Used in message routing.

Parameters:

contentType - the content type of the message. May be null if you don't want to specify a content type.

setCorrelatingMessageCallback

public void setCorrelatingMessageCallback(CorrelatingMessageCallback correlatingMessageCallback)

Parameters:

correlatingMessageCallback

setCorrelatingMessageCallbackContext

public void setCorrelatingMessageCallbackContext(Object correlatingMessageCallbackContext)

Parameters:

correlatingMessageCallbackContext

setCorrelationId

public void setCorrelationId(String correlationId)

Setter for the correlationId property

Parameters:

correlationId - The string containing the property value

setCreationTimeUTC

public final void setCreationTimeUTC(Date creationTimeUTC)

Parameters:

creationTimeUTC

setExpiryTime

public void setExpiryTime(long timeOut)

Setter for the expiryTime property. This setter uses relative time, not absolute time.

Parameters:

timeOut - The time out for the message, in milliseconds, from the current time.

setInputName

public void setInputName(String inputName)

Set the input name of the message, used in routing for module communications

Parameters:

inputName - the input channel the message was received from

setIotHubConnectionString

public void setIotHubConnectionString(IotHubConnectionString iotHubConnectionString)

Setter for the iotHubConnectionString type

Parameters:

iotHubConnectionString - The iotHubConnectionString value to set

setMessageId

public void setMessageId(String messageId)

Setter for the messageId property

Parameters:

messageId - The string containing the property value

setMessageType

public void setMessageType(MessageType type)

Setter for the Message type

Parameters:

type - The enum containing the Message type value

setOutputName

public void setOutputName(String outputName)

Set the output channel name to send to. Used in routing for module communications

Parameters:

outputName - the output channel name to send to

setProperty

public void setProperty(String name, String value)

Adds or sets user-defined properties of this Message.

Parameters:

name - Name of the property to be set.
value - Value of the property to be set.

Throws:

IllegalArgumentException - If any of the arguments provided is null.

setUserId

public void setUserId(String userId)

Parameters:

userId

toString

public String toString()

Applies to