public class MessageTemplate extends Object implements InitializingBean, BeanFactoryAware
AsyncMessage
s from a Java client. The message will be routed through the
MessageBroker
to the specified MessageDestination
. This allows for flexible routing of the message
using whatever MessagingAdapter
is configured for the target destination, be it the basic BlazeDS
ActionScriptAdapter
, one of the provided Spring adapters such as JmsAdapter
or IntegrationAdapter
, or some other custom adapter implementation.
This class should typically be configured as a Spring bean in the same ApplicationContext as the <flex:message-broker> tag
to allow injection of a Spring-managed MessageBroker
instance. When a single MessageBroker
is detected in the
ApplicationContext, it will be automatically injected into the MessageTemplate bean. If more than one MessageBroker
is
present (not typical), a reference to the correct MessageBroker
must be explicitly set for the setMessageBroker(MessageBroker)
property.
The MessageTemplate
may also be instantiated directly, in which case it will try to look up the ThreadLocal
MessageBroker
instance for the current request, but configuration as a Spring bean is strongly preferred.
Constructor and Description |
---|
MessageTemplate() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
flex.messaging.messages.AsyncMessage |
createMessage()
Creates a default
AsyncMessage |
flex.messaging.messages.AsyncMessage |
createMessageForDestination(String destination)
Creates a default
AsyncMessage for a specified destination |
String |
getDefaultDestination()
Returns the id of the default message destination for this template
|
flex.messaging.MessageBroker |
getMessageBroker()
Returns the
MessageBroker for routing messages |
void |
send(AsyncMessageCreator creator)
Sends a message created by the specified
AsyncMessageCreator |
void |
send(Object body)
Sends a message with the specified body to the default destination.
|
void |
send(String destination,
Object body)
Sends a message with the specified body to the specified destination
|
void |
setBeanFactory(BeanFactory beanFactory) |
void |
setDefaultDestination(String defaultDestination)
Sets the id of the default message destination for this template
|
void |
setMessageBroker(flex.messaging.MessageBroker messageBroker)
Sets the
MessageBroker for routing messages |
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
public flex.messaging.messages.AsyncMessage createMessage()
AsyncMessage
public flex.messaging.messages.AsyncMessage createMessageForDestination(String destination)
AsyncMessage
for a specified destinationdestination
- the target destination for the messagepublic String getDefaultDestination()
public flex.messaging.MessageBroker getMessageBroker()
MessageBroker
for routing messagespublic void send(AsyncMessageCreator creator)
AsyncMessageCreator
creator
- the message creatorpublic void send(Object body)
body
- the body of the messagepublic void send(String destination, Object body)
destination
- the target destination idbody
- the body of the messagepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory
in interface BeanFactoryAware
BeansException
public void setDefaultDestination(String defaultDestination)
defaultDestination
- the default destination idpublic void setMessageBroker(flex.messaging.MessageBroker messageBroker)
MessageBroker
for routing messagesmessageBroker
- the message brokerCopyright © 2014. All rights reserved.