Spring AMQP

org.springframework.amqp.rabbit.core
Class RabbitTemplate

java.lang.Object
  extended by org.springframework.amqp.rabbit.support.RabbitAccessor
      extended by org.springframework.amqp.rabbit.core.RabbitTemplate
All Implemented Interfaces:
AmqpTemplate, RabbitOperations, InitializingBean

public class RabbitTemplate
extends RabbitAccessor
implements RabbitOperations

Helper class that simplifies synchronous RabbitMQ access code.

Author:
Mark Pollack, Mark Fisher

Field Summary
 
Fields inherited from class org.springframework.amqp.rabbit.support.RabbitAccessor
logger
 
Constructor Summary
RabbitTemplate()
           
RabbitTemplate(ConnectionFactory connectionFactory)
           
 
Method Summary
 void convertAndSend(Object object)
           
 void convertAndSend(Object message, MessagePostProcessor messagePostProcessor)
           
 void convertAndSend(String routingKey, Object object)
           
 void convertAndSend(String routingKey, Object message, MessagePostProcessor messagePostProcessor)
           
 void convertAndSend(String exchange, String routingKey, Object object)
           
 void convertAndSend(String exchange, String routingKey, Object message, MessagePostProcessor messagePostProcessor)
           
 Object convertSendAndReceive(Object message)
           
 Object convertSendAndReceive(String routingKey, Object message)
           
 Object convertSendAndReceive(String exchange, String routingKey, Object message)
           
<T> T
execute(ChannelCallback<T> action)
           
 MessageConverter getMessageConverter()
          Return the message converter for this template.
protected  void initDefaultStrategies()
           
protected  boolean isChannelLocallyTransacted(com.rabbitmq.client.Channel channel)
          Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this template's Channel handling and not by an external transaction coordinator.
 Message receive()
           
 Message receive(String queueName)
           
 Object receiveAndConvert()
           
 Object receiveAndConvert(String queueName)
           
 void send(Message message)
           
 void send(String routingKey, Message message)
           
 void send(String exchange, String routingKey, Message message)
           
 void setExchange(String exchange)
           
 void setMessageConverter(MessageConverter messageConverter)
          Set the message converter for this template.
 void setQueue(String queue)
           
 void setReplyTimeout(long replyTimeout)
          Specify the timeout in milliseconds to be used when waiting for a reply Message when using one of the sendAndReceive methods.
 void setRoutingKey(String routingKey)
           
 
Methods inherited from class org.springframework.amqp.rabbit.support.RabbitAccessor
afterPropertiesSet, convertRabbitAccessException, createChannel, createConnection, getChannel, getConnection, getConnectionFactory, getTransactionalResourceHolder, isChannelTransacted, setChannelTransacted, setConnectionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RabbitTemplate

public RabbitTemplate()

RabbitTemplate

public RabbitTemplate(ConnectionFactory connectionFactory)
Method Detail

initDefaultStrategies

protected void initDefaultStrategies()

setExchange

public void setExchange(String exchange)

setRoutingKey

public void setRoutingKey(String routingKey)

setQueue

public void setQueue(String queue)

setReplyTimeout

public void setReplyTimeout(long replyTimeout)
Specify the timeout in milliseconds to be used when waiting for a reply Message when using one of the sendAndReceive methods. The default value is defined as DEFAULT_REPLY_TIMEOUT. A negative value indicates an indefinite timeout.


setMessageConverter

public void setMessageConverter(MessageConverter messageConverter)
Set the message converter for this template. Used to resolve Object parameters to convertAndSend methods and Object results from receiveAndConvert methods.

The default converter is a SimpleMessageConverter, which is able to handle byte arrays, Strings, and Serializable Objects.

See Also:
convertAndSend(java.lang.Object), receiveAndConvert(), SimpleMessageConverter

getMessageConverter

public MessageConverter getMessageConverter()
Return the message converter for this template.


send

public void send(Message message)
          throws AmqpException
Specified by:
send in interface AmqpTemplate
Throws:
AmqpException

send

public void send(String routingKey,
                 Message message)
          throws AmqpException
Specified by:
send in interface AmqpTemplate
Throws:
AmqpException

send

public void send(String exchange,
                 String routingKey,
                 Message message)
          throws AmqpException
Specified by:
send in interface AmqpTemplate
Throws:
AmqpException

convertAndSend

public void convertAndSend(Object object)
                    throws AmqpException
Specified by:
convertAndSend in interface AmqpTemplate
Throws:
AmqpException

convertAndSend

public void convertAndSend(String routingKey,
                           Object object)
                    throws AmqpException
Specified by:
convertAndSend in interface AmqpTemplate
Throws:
AmqpException

convertAndSend

public void convertAndSend(String exchange,
                           String routingKey,
                           Object object)
                    throws AmqpException
Specified by:
convertAndSend in interface AmqpTemplate
Throws:
AmqpException

convertAndSend

public void convertAndSend(Object message,
                           MessagePostProcessor messagePostProcessor)
                    throws AmqpException
Specified by:
convertAndSend in interface AmqpTemplate
Throws:
AmqpException

convertAndSend

public void convertAndSend(String routingKey,
                           Object message,
                           MessagePostProcessor messagePostProcessor)
                    throws AmqpException
Specified by:
convertAndSend in interface AmqpTemplate
Throws:
AmqpException

convertAndSend

public void convertAndSend(String exchange,
                           String routingKey,
                           Object message,
                           MessagePostProcessor messagePostProcessor)
                    throws AmqpException
Specified by:
convertAndSend in interface AmqpTemplate
Throws:
AmqpException

receive

public Message receive()
                throws AmqpException
Specified by:
receive in interface AmqpTemplate
Throws:
AmqpException

receive

public Message receive(String queueName)
Specified by:
receive in interface AmqpTemplate

receiveAndConvert

public Object receiveAndConvert()
                         throws AmqpException
Specified by:
receiveAndConvert in interface AmqpTemplate
Throws:
AmqpException

receiveAndConvert

public Object receiveAndConvert(String queueName)
                         throws AmqpException
Specified by:
receiveAndConvert in interface AmqpTemplate
Throws:
AmqpException

convertSendAndReceive

public Object convertSendAndReceive(Object message)
                             throws AmqpException
Specified by:
convertSendAndReceive in interface AmqpTemplate
Throws:
AmqpException

convertSendAndReceive

public Object convertSendAndReceive(String routingKey,
                                    Object message)
                             throws AmqpException
Throws:
AmqpException

convertSendAndReceive

public Object convertSendAndReceive(String exchange,
                                    String routingKey,
                                    Object message)
                             throws AmqpException
Throws:
AmqpException

execute

public <T> T execute(ChannelCallback<T> action)
Specified by:
execute in interface RabbitOperations

isChannelLocallyTransacted

protected boolean isChannelLocallyTransacted(com.rabbitmq.client.Channel channel)
Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this template's Channel handling and not by an external transaction coordinator.

Parameters:
channel - the Channel to check
Returns:
whether the given Channel is locally transacted
See Also:
ConnectionFactoryUtils.isChannelTransactional(com.rabbitmq.client.Channel, org.springframework.amqp.rabbit.connection.ConnectionFactory), RabbitAccessor.isChannelTransacted()

Spring AMQP

Copyright © 2010. All Rights Reserved.