Message Content Prototype
Introduction
To address
- the complete separation of message content from the transport,
- the fixed required control system message header,
- additional, typed header fields and
- easy to use, flexible message data blobs
a
CsMessage
type to use in JAVA and C++ is the base to access and transport data in control system messages. It
- forces the developer to provide the required header data,
- allows the developer to add custom typed header fields, aka properties and
- provides two content bodies of the types
If used the bodies have to be in
standardized formats. The messaging system provides ways to read/write these formats using supported programming languages.
Note: We cannot force anybody to use such message formats - anyone can still send e.g. plain JMS
BytesMessages. Therefore we should suggest an attractive guideline that people would
like to follow.
Interface
Access methods for all parts of the message content are provided. As an example here is the JAVA interface (the C++ one provides exactly the same functionality):
package de.gsi.bel.csmsg;
public interface CsMessage
{
// access header
public String getType();
public String getVersion();
public String getSender();
public String getReceiver();
// access properties
public boolean getBooleanProperty(String key) throws CsMessageException;
public long getLongProperty(String key) throws CsMessageException;
public double getDoubleProperty(String key) throws CsMessageException;
public String getStringProperty(String key) throws CsMessageException;
public boolean propertyExists(String key);
// access bodies
public byte[] getByteBody() throws CsMessageException;
public String getStringBody() throws CsMessageException;
// set header; required
public void setType(String type);
public void setVersion(String version);
public void setSender(String sender);
public void setReceiver(String receiver);
// add properties; optional
public void setBooleanProperty(String key, boolean val);
public void setLongProperty(String key, long val);
public void setDoubleProperty(String key, double val);
public void setStringProperty(String key, String val);
// set bodies; optional
public void setByteBody(byte[] body);
public void setStringBody(String body);
// read write byte blob to transport
public byte[] toDump() throws CsMessageException;
public void fromDump(byte[] bytes) throws CsMessageException;
}
Body formats
The choice of body formats - either JSON or protocol buffers - is based on
this.
Such a message is transported as a binary blob which can be handled by all messaging technology. A CsMessage provides the functionality to de/serialize it to/from a byte array as indicated above.
The de/serialization from/to the blob is done using protocol buffers, i.e. there is a protocol buffers message that
- requires the fixed header fields,
- de/encodes the dynamic properties as a JSON string and
- provides two byte array fields for the bodies.