public abstract class Message
extends java.lang.Object
Event messages are sent using the DxlClient.sendEvent(com.opendxl.client.message.Event)
method of a client instance. Event messages are sent
by one publisher and received by one or more recipients that are currently subscribed to the
getDestinationTopic()
associated with the event (otherwise known as one-to-many).
Request messages are sent using the DxlClient.syncRequest(com.opendxl.client.message.Request)
and DxlClient.asyncRequest(com.opendxl.client.message.Request, com.opendxl.client.callback.ResponseCallback, long)
methods of a
client instance. Request messages are used when invoking a method on a remote service. This communication is
one-to-one where a client sends a request to a service instance and in turn receives a response.
Response messages are sent by service instances upon receiving Request messages. Response messages are sent using
the DxlClient.sendResponse(com.opendxl.client.message.Response)
method of a client instance. Clients that are invoking the service (sending a
request) will receive the response as a return value of the DxlClient.syncRequest(com.opendxl.client.message.Request)
method of a client
instance or via the ResponseCallback
callback when invoking the asynchronous method,
DxlClient.asyncRequest(com.opendxl.client.message.Request, com.opendxl.client.callback.ResponseCallback, long)
.
ErrorResponse
messages are sent by the DXL fabric itself or service instances upon receiving Request
messages. The error response may indicate the inability to locate a service to handle the request or an internal
error within the service itself. Error response messages are sent using the DxlClient.sendResponse(com.opendxl.client.message.Response)
method
of a client instance.
NOTE: Some services may chose to not send a Response message when receiving a Request. This typically occurs
if the service is being used to simply collect information from remote clients. In this scenario, the client should
use the asynchronous form for sending requests, DxlClient.asyncRequest(com.opendxl.client.message.Request, com.opendxl.client.callback.ResponseCallback, long)
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CHARSET_ASCII
ASCII character encoding
|
static java.lang.String |
CHARSET_UTF8
UTF-8 character encoding
|
static byte |
MESSAGE_TYPE_ERROR
The numeric type identifier for the
ErrorResponse message type |
static byte |
MESSAGE_TYPE_EVENT
The numeric type identifier for the
Event message type |
static byte |
MESSAGE_TYPE_REQUEST
The numeric type identifier for the
Request message type |
static byte |
MESSAGE_TYPE_RESPONSE
The numeric type identifier for the
Response message type |
static long |
MESSAGE_VERSION
The message version
|
Constructor and Description |
---|
Message(DxlClient client,
java.lang.String destinationTopic)
Constructor for
Message |
Message(java.lang.String destinationTopic)
Constructor for
Message |
Message(java.lang.String sourceClientId,
java.lang.String destinationTopic)
Constructor for
Message |
Modifier and Type | Method and Description |
---|---|
static Message |
fromBytes(byte[] bytes)
Converts the specified array of bytes to a concrete message instance (request, response, error, etc.)
and returns it
|
java.util.Set<java.lang.String> |
getBrokerIds()
Returns the broker identifiers that the message is to be routed to.
|
java.util.Set<java.lang.String> |
getClientIds()
Returns the client identifiers that the message is to be routed to
|
java.lang.String |
getDestinationTopic()
Returns the topic to publish the message to
|
java.util.Set<java.lang.String> |
getDestTenantGuids()
Returns the set of tenant identifiers that the message is to be routed to.
|
java.lang.String |
getMessageId()
Returns the unique identifier for the message (UUID)
|
static org.msgpack.MessagePack |
getMessagePack()
Returns the message pack instance to use for packing/unpacking messages
|
abstract byte |
getMessageType()
Returns the numeric type of the message
|
java.util.Map<java.lang.String,java.lang.String> |
getOtherFields()
Returns a
Map containing the set of additional fields associated with the message. |
byte[] |
getPayload()
Returns the application-specific payload of the message (bytes)
|
java.lang.String |
getSourceBrokerId()
Returns the identifier of the DXL broker that the message's originating client is connected to (set by the
initial broker)
|
java.lang.String |
getSourceClientId()
Returns the identifier of the DXL client that sent the message (set by the broker that initially receives
the message)
|
java.lang.String |
getSourceClientInstanceId()
Returns the instance identifier for the client that is the source of the message
|
java.lang.String |
getSourceTenantGuid()
Returns the tenant identifier of the DXL client that sent the message (set by the broker that initially
receives the message)
|
long |
getVersion()
Returns the version of the DXL message (used to determine the features that are available)
|
void |
setBrokerIds(java.util.Set<java.lang.String> brokerIds)
Sets the broker identifiers that the message is to be routed to.
|
void |
setClientIds(java.util.Set<java.lang.String> clientIds)
Sets the client identifiers that the message is to be routed to.
|
void |
setDestinationTopic(java.lang.String topic)
Sets the topic to publish the message to
|
void |
setDestTenantGuids(java.util.Set<java.lang.String> destTenantGuids)
Sets the tenant identifiers that the message is to be routed to.
|
void |
setOtherFields(java.util.Map<java.lang.String,java.lang.String> otherFields)
Sets a
Map containing the set of additional fields associated with the message. |
void |
setPayload(byte[] payload)
The payload for the message
|
void |
setSourceClientId(java.lang.String sourceClientId)
Sets the identifier of the DXL client that sent the message (set by the broker that initially receives
the message)
|
void |
setSourceClientInstanceId(java.lang.String sourceClientInstanceId)
Sets the instance identifier for the client that is the source of the message
|
void |
setSourceTenantGuid(java.lang.String sourceTenantGuid)
Sets the tenant identifier of the DXL client that sent the message (set by the broker that initially receives
the message)
|
byte[] |
toBytes()
Converts the message to an array of bytes and returns it
|
public static final java.lang.String CHARSET_ASCII
public static final java.lang.String CHARSET_UTF8
public static final long MESSAGE_VERSION
Version history
Version 0:
1.0 to version 1.1:
Standard fields.
Version 1:
2.0+:
Added "other" fields (string array)
Version 2:
3.1+:
Added "sourceTenantGuid" field (string)
Added "tenantGuids" fields (string array)
Version 3:
5.0+:
Added "sourceClientInstanceId" to support multiple
connections per client (string).
public static final byte MESSAGE_TYPE_REQUEST
Request
message typepublic static final byte MESSAGE_TYPE_RESPONSE
Response
message typepublic static final byte MESSAGE_TYPE_EVENT
Event
message typepublic static final byte MESSAGE_TYPE_ERROR
ErrorResponse
message typepublic Message(DxlClient client, java.lang.String destinationTopic)
Message
client
- The client that will be sending this messagedestinationTopic
- The topic to publish the message topublic Message(java.lang.String destinationTopic)
Message
destinationTopic
- The topic to publish the message topublic Message(java.lang.String sourceClientId, java.lang.String destinationTopic)
Message
sourceClientId
- The identifier of the client that will be sending this messagedestinationTopic
- The topic to publish the message topublic long getVersion()
public abstract byte getMessageType()
public java.lang.String getMessageId()
public java.lang.String getSourceClientId()
public void setSourceClientId(java.lang.String sourceClientId)
sourceClientId
- The identifier of the DXL client that sent the message (set by the broker that initially
receives the message)public void setSourceClientInstanceId(java.lang.String sourceClientInstanceId)
sourceClientInstanceId
- The instance identifier for the client that is the source of the messagepublic java.lang.String getSourceClientInstanceId()
public java.lang.String getSourceBrokerId()
public java.lang.String getDestinationTopic()
public void setDestinationTopic(java.lang.String topic)
topic
- The topic to publish the message topublic void setPayload(byte[] payload)
payload
- The payload for the messagepublic byte[] getPayload()
public void setBrokerIds(java.util.Set<java.lang.String> brokerIds)
setClientIds(java.util.Set<java.lang.String>)
.brokerIds
- The broker identifiers that the message is to be routed topublic java.util.Set<java.lang.String> getBrokerIds()
public void setClientIds(java.util.Set<java.lang.String> clientIds)
setBrokerIds(java.util.Set<java.lang.String>)
.clientIds
- The client GUIDs to send the message topublic java.util.Set<java.lang.String> getClientIds()
public void setOtherFields(java.util.Map<java.lang.String,java.lang.String> otherFields)
Map
containing the set of additional fields associated with the message. These fields can be
used to add "header" like values to the message without requiring modifications to be made to the payload.otherFields
- A Map
containing the set of additional fields associated with the message.public java.util.Map<java.lang.String,java.lang.String> getOtherFields()
Map
containing the set of additional fields associated with the message. These fields can be
used to add "header" like values to the message without requiring modifications to be made to the payload.Map
containing the set of additional fields associated with the message.public java.lang.String getSourceTenantGuid()
public void setSourceTenantGuid(java.lang.String sourceTenantGuid)
sourceTenantGuid
- The tenant identifier of the DXL client that sent the message (set by the broker that
initially receives the message)public java.util.Set<java.lang.String> getDestTenantGuids()
public void setDestTenantGuids(java.util.Set<java.lang.String> destTenantGuids)
setBrokerIds(java.util.Set<java.lang.String>)
and
setClientIds(java.util.Set<java.lang.String>)
.destTenantGuids
- The set of tenant identifiers that the message is to be routed to.public final byte[] toBytes() throws java.io.IOException
java.io.IOException
- If an IO exception occurspublic static Message fromBytes(byte[] bytes) throws java.io.IOException
bytes
- The message as an array of bytesjava.io.IOException
- If an IO exception occurspublic static org.msgpack.MessagePack getMessagePack()