CommandMessage represents a message payload. It implements a builder (or fluent) API which is used for constructing sendable messages. It is the core messageing API for ErraiBus, and will be the foremost used class within ErraiBus by most users.
Example Message: CommandMessage msg = CommandMessage.create() .toSubject("Foo") .set("Text", "I like chocolate cake.");
You can transmit a message using the the
sendNowWith() method by providing an instance of {@link org.jboss.errai.bus.client.framework.MessageBus}.
Messages can be contructed using user-defined standard protocols through the use of enumerations. Both
commandType and message parts can be defined through the use of enumerations. This helps create strongly-defined protocols for communicating with services. For instance:
public enum LoginParts { Username, Password }
.. and ..
public enum LoginCommands { Login, Logout }
These enumerations can than be directly used to build messages and decode incoming messages by a service. For example:
CommandMessage.create() .command(LoginCommands.Login) .set(LoginParts.Username, "foo") .set(LoginParts.Password, "bar ) .sendNowWith(busInstance);
Messages may contain serialized objects provided they meet the following criteria:
- The class is annotated with {@link org.jboss.errai.bus.server.annotations.ExposeEntity}
- The class implements {@link java.io.Serializable}.
- The class contains a default, no-argument constructor.
@see ConversationMessage