Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Spring BlazeDS Integration
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.flex.messaging
Class MessageTemplate

    java.lang.Object
      org.springframework.flex.messaging.MessageTemplate

All Implemented Interfaces:
  BeanFactoryAware, InitializingBean

    public class MessageTemplate

extends Object
implements InitializingBean, BeanFactoryAware

Simple helper for sending Flex `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.

Author:
  Jeremy Grelle

Constructor Summary
`MessageTemplate()`

Method Summary
`void` | `afterPropertiesSet()`
`AsyncMessage` | `createMessage()` Creates a default `AsyncMessage`
`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
`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(MessageBroker messageBroker)` Sets the `MessageBroker` for routing messages

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MessageTemplate

    public MessageTemplate()

Method Detail

### afterPropertiesSet

    public void afterPropertiesSet()
                            throws Exception

  Specified by:
    `afterPropertiesSet` in interface `InitializingBean`
  Throws:
    `Exception`

### createMessage

    public AsyncMessage createMessage()

  Creates a default `AsyncMessage`

  Returns:
    the created message

### createMessageForDestination

    public AsyncMessage createMessageForDestination(String destination)

  Creates a default `AsyncMessage` for a specified destination

  Parameters:
    `destination` - the target destination for the message
  Returns:
    the created message

### getDefaultDestination

    public String getDefaultDestination()

  Returns the id of the default message destination for this template

  Returns:
    the default destination id

### getMessageBroker

    public MessageBroker getMessageBroker()

  Returns the `MessageBroker` for routing messages

  Returns:
    the message broker

### send

    public void send(AsyncMessageCreator creator)

  Sends a message created by the specified `AsyncMessageCreator`

  Parameters:
    `creator` - the message creator

### send

    public void send(Object body)

  Sends a message with the specified body to the default destination.

  Parameters:
    `body` - the body of the message

### send

    public void send(String destination,
                     Object body)

  Sends a message with the specified body to the specified destination

  Parameters:
    `destination` - the target destination id
    `body` - the body of the message

### setBeanFactory

    public void setBeanFactory(BeanFactory beanFactory)
                        throws BeansException

  Specified by:
    `setBeanFactory` in interface `BeanFactoryAware`
  Throws:
    `BeansException`

### setDefaultDestination

    public void setDefaultDestination(String defaultDestination)

  Sets the id of the default message destination for this template

  Parameters:
    `defaultDestination` - the default destination id

### setMessageBroker

    public void setMessageBroker(MessageBroker messageBroker)

  Sets the `MessageBroker` for routing messages

  Parameters:
    `messageBroker` - the message broker

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Spring BlazeDS Integration
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011. All Rights Reserved.