org.springframework.integration.jms
Class JmsDestinationBackedMessageChannel

java.lang.Object
  extended by org.springframework.integration.jms.JmsDestinationBackedMessageChannel
All Implemented Interfaces:
javax.jms.MessageListener, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, SubscribableChannel, MessageChannel

public class JmsDestinationBackedMessageChannel
extends java.lang.Object
implements SubscribableChannel, javax.jms.MessageListener, org.springframework.beans.factory.BeanNameAware, org.springframework.context.SmartLifecycle, org.springframework.beans.factory.InitializingBean

A MessageChannel implementation that is actually backed by a JMS Destination. This class is useful as a drop-in replacement for any Spring Integration channel. The benefit of using this channel is that the full power of any JMS provider is available with only minimal configuration changes and without requiring any code changes. The most obvious benefit is the ability to delegate message persistence to the JMS provider.

Since:
2.0
Author:
Mark Fisher

Constructor Summary
JmsDestinationBackedMessageChannel(javax.jms.ConnectionFactory connectionFactory, javax.jms.Destination destination)
           
JmsDestinationBackedMessageChannel(javax.jms.ConnectionFactory connectionFactory, java.lang.String destinationName, boolean isPubSub)
           
JmsDestinationBackedMessageChannel(javax.jms.ConnectionFactory connectionFactory, java.lang.String destinationName, boolean isPubSub, org.springframework.jms.support.destination.DestinationResolver destinationResolver)
           
 
Method Summary
 void afterPropertiesSet()
           
 java.lang.String getName()
          Return the name of this channel.
 int getPhase()
           
 boolean isAutoStartup()
           
 boolean isRunning()
           
 void onMessage(javax.jms.Message message)
           
 boolean send(Message<?> message)
          Send a Message to this channel.
 boolean send(Message<?> message, long timeout)
          Send a message, blocking until either the message is accepted or the specified timeout period elapses.
 void setBeanName(java.lang.String beanName)
           
 void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
           
 void start()
           
 void stop()
           
 void stop(java.lang.Runnable callback)
           
 boolean subscribe(MessageHandler handler)
          Register a MessageHandler as a subscriber to this channel.
 boolean unsubscribe(MessageHandler handler)
          Remove a MessageHandler from the subscribers of this channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmsDestinationBackedMessageChannel

public JmsDestinationBackedMessageChannel(javax.jms.ConnectionFactory connectionFactory,
                                          javax.jms.Destination destination)

JmsDestinationBackedMessageChannel

public JmsDestinationBackedMessageChannel(javax.jms.ConnectionFactory connectionFactory,
                                          java.lang.String destinationName,
                                          boolean isPubSub)

JmsDestinationBackedMessageChannel

public JmsDestinationBackedMessageChannel(javax.jms.ConnectionFactory connectionFactory,
                                          java.lang.String destinationName,
                                          boolean isPubSub,
                                          org.springframework.jms.support.destination.DestinationResolver destinationResolver)
Method Detail

setBeanName

public void setBeanName(java.lang.String beanName)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

setTransactionManager

public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

getName

public java.lang.String getName()
Description copied from interface: MessageChannel
Return the name of this channel.

Specified by:
getName in interface MessageChannel

subscribe

public boolean subscribe(MessageHandler handler)
Description copied from interface: SubscribableChannel
Register a MessageHandler as a subscriber to this channel.

Specified by:
subscribe in interface SubscribableChannel

unsubscribe

public boolean unsubscribe(MessageHandler handler)
Description copied from interface: SubscribableChannel
Remove a MessageHandler from the subscribers of this channel.

Specified by:
unsubscribe in interface SubscribableChannel

send

public boolean send(Message<?> message)
Description copied from interface: MessageChannel
Send a Message to this channel. May throw a RuntimeException for non-recoverable errors. Otherwise, if the Message cannot be sent for a non-fatal reason this method will return 'false', and if the Message is sent successfully, it will return 'true'.

Depending on the implementation, this method may block indefinitely. To provide a maximum wait time, use MessageChannel.send(Message, long).

Specified by:
send in interface MessageChannel
Parameters:
message - the Message to send
Returns:
whether the Message has been sent successfully

send

public boolean send(Message<?> message,
                    long timeout)
Description copied from interface: MessageChannel
Send a message, blocking until either the message is accepted or the specified timeout period elapses.

Specified by:
send in interface MessageChannel
Parameters:
message - the Message to send
timeout - the timeout in milliseconds
Returns:
true if the message is sent successfully, false if the specified timeout period elapses or the send is interrupted

onMessage

public void onMessage(javax.jms.Message message)
Specified by:
onMessage in interface javax.jms.MessageListener

getPhase

public int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

isRunning

public boolean isRunning()
Specified by:
isRunning in interface org.springframework.context.Lifecycle

start

public void start()
Specified by:
start in interface org.springframework.context.Lifecycle

stop

public void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

stop

public void stop(java.lang.Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle