public class MessageBuilder extends Object
Message m = MessageBuilder .createMessage() .toSubject("TheMessageSubject") .withValue("Hello everyone").done();
You can transmit a message using the the sendNowWith(RequestDispatcher) method by providing an instance of
MessageBus
.
Messages can be constructed 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 }A service can then use these enumerations to build and decode messages. For example:
MessageBuilder .createMessage() .toSubject("LoginService") .command(LoginCommands.Login) .set(LoginParts.Username, "foo") .set(LoginParts.Password, "bar") .sendNowWith(busInstance);Messages may contain serialized objects that are annotated with
Portable
and can be marshalled by the built-in Errai
marshallers or by user-provided marshallers that have been registered with the system.Constructor and Description |
---|
MessageBuilder() |
Modifier and Type | Method and Description |
---|---|
static DefaultRemoteCallBuilder |
createCall()
Creates an AbstractRemoteCallBuilder to construct a call.
|
static <R,T> T |
createCall(RemoteCallback<R> callback,
BusErrorCallback errorCallback,
Class<T> service)
Creates an RPC call with error handling.
|
static <R,T> T |
createCall(RemoteCallback<R> callback,
Class<T> service)
Creates an RPC call, with no error handling.
|
static MessageBuildSubject<MessageReplySendable> |
createConversation(Message message)
Creates a conversational message.
|
static MessageBuildCommand<MessageReplySendable> |
createConversation(Message message,
String subject)
Creates a conversational message for the provided subject.
|
static MessageBuildSubject<MessageBuildSendableWithReply> |
createMessage()
Creates a new message.
|
static MessageBuildCommand<MessageBuildSendableWithReply> |
createMessage(String subject)
Creates a new message for the provided subject.
|
static MessageProvider |
getMessageProvider()
Returns the message provider.
|
static void |
setMessageProvider(MessageProvider provider)
Sets the message provider for this instance of MessageBuilder.
|
public static MessageBuildSubject<MessageBuildSendableWithReply> createMessage()
public static MessageBuildCommand<MessageBuildSendableWithReply> createMessage(String subject)
subject
- the subject the message should be sent topublic static MessageBuildSubject<MessageReplySendable> createConversation(Message message)
message
- reference message to create conversation frompublic static MessageBuildCommand<MessageReplySendable> createConversation(Message message, String subject)
message
- reference message to create conversation fromsubject
- the subject the message should be sent topublic static DefaultRemoteCallBuilder createCall()
public static <R,T> T createCall(RemoteCallback<R> callback, Class<T> service)
T
- The type of the remote service.R
- The return type of the invoked method.callback
- The remote callback that receives the return value from the call. Cannot not be null.service
- The remote interface.public static <R,T> T createCall(RemoteCallback<R> callback, BusErrorCallback errorCallback, Class<T> service)
T
- The type of the remote service.R
- The return type of the invoked method.callback
- The remote callback that receives the return value from the call. Cannot not be null.errorCallback
- The error callback that receives transmission errors and exceptions thrown by the remote service. Cannot not be null.service
- The remote interface.public static void setMessageProvider(MessageProvider provider)
provider
- to set this' provider topublic static MessageProvider getMessageProvider()
Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.