Spring AMQP

org.springframework.amqp.support.converter
Class MarshallingMessageConverter

java.lang.Object
  extended by org.springframework.amqp.support.converter.MarshallingMessageConverter
All Implemented Interfaces:
MessageConverter, InitializingBean

public class MarshallingMessageConverter
extends Object
implements MessageConverter, InitializingBean

Spring Rabbit MessageConverter that uses a Marshaller and Unmarshaller. Marshals an object to a Message and unmarshals a Message to an object.

Author:
Mark Fisher, Arjen Poutsma, Juergen Hoeller
See Also:
RabbitTemplate.convertAndSend(java.lang.Object), RabbitTemplate.receiveAndConvert()

Constructor Summary
MarshallingMessageConverter()
          Construct a new MarshallingMessageConverter with no Marshaller or Unmarshaller set.
MarshallingMessageConverter(Marshaller marshaller)
          Construct a new MarshallingMessageConverter with the given Marshaller set.
MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
          Construct a new MarshallingMessageConverter with the given Marshaller and Unmarshaller.
 
Method Summary
 void afterPropertiesSet()
           
 Object fromMessage(Message message)
          Unmarshals the given Message into an object.
 void setMarshaller(Marshaller marshaller)
          Set the Marshaller to be used by this message converter.
 void setUnmarshaller(Unmarshaller unmarshaller)
          Set the Unmarshaller to be used by this message converter.
 Message toMessage(Object object, MessageProperties messageProperties)
          Marshals the given object to a Message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarshallingMessageConverter

public MarshallingMessageConverter()
Construct a new MarshallingMessageConverter with no Marshaller or Unmarshaller set. The marshaller must be set after construction by invoking setMarshaller(Marshaller) and setUnmarshaller(Unmarshaller) .


MarshallingMessageConverter

public MarshallingMessageConverter(Marshaller marshaller)
Construct a new MarshallingMessageConverter with the given Marshaller set.

If the given Marshaller also implements the Unmarshaller interface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.

Note that all Marshaller implementations in Spring also implement the Unmarshaller interface, so that you can safely use this constructor.

Parameters:
marshaller - object used as marshaller and unmarshaller
Throws:
IllegalArgumentException - when marshaller does not implement the Unmarshaller interface as well

MarshallingMessageConverter

public MarshallingMessageConverter(Marshaller marshaller,
                                   Unmarshaller unmarshaller)
Construct a new MarshallingMessageConverter with the given Marshaller and Unmarshaller.

Parameters:
marshaller - the Marshaller to use
unmarshaller - the Unmarshaller to use
Method Detail

setMarshaller

public void setMarshaller(Marshaller marshaller)
Set the Marshaller to be used by this message converter.


setUnmarshaller

public void setUnmarshaller(Unmarshaller unmarshaller)
Set the Unmarshaller to be used by this message converter.


afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

toMessage

public Message toMessage(Object object,
                         MessageProperties messageProperties)
                  throws MessageConversionException
Marshals the given object to a Message.

Specified by:
toMessage in interface MessageConverter
Parameters:
object - the object to convert
Returns:
the Rabbit Message
Throws:
MessageConversionException - in case of conversion failure

fromMessage

public Object fromMessage(Message message)
                   throws MessageConversionException
Unmarshals the given Message into an object.

Specified by:
fromMessage in interface MessageConverter
Parameters:
message - the message to convert
Returns:
the converted Java object
Throws:
MessageConversionException - in case of conversion failure

Spring AMQP

Copyright © 2010. All Rights Reserved.