By default, the content of incoming Rabbit messages gets extracted before being passed into the target listener method, to let the target method operate on message content types such as String or byte array instead of the raw {@link Message}. Message type conversion is delegated to a Spring AMQ {@link MessageConverter}. By default, a {@link SimpleMessageConverter} will be used. (If you do not want such automatic message conversion taking place, thenbe sure to set the {@link #setMessageConverter MessageConverter} to null
.)
If a target listener method returns a non-null object (typically of a message content type such as String
or byte array), it will get wrapped in a Rabbit Message
and sent to the exchange of the incoming message with the routingKey that comes from the Rabbit ReplyTo property or via {@link #setResponseRoutingKey(String) specified routingKey}).
Note: The sending of response messages is only available when using the {@link ChannelAwareMessageListener}entry point (typically through a Spring message listener container). Usage as {@link MessageListener} does notsupport the generation of response messages.
Find below some examples of method signatures compliant with this adapter class. This first example handles all Message
types and gets passed the contents of each Message
type as an argument. No Message
will be sent back as all of these methods return void
.
public interface MessageContentsDelegate { void handleMessage(String text); void handleMessage(Map map); void handleMessage(byte[] bytes); void handleMessage(Serializable obj); }This next example handle a
Message
type and gets passed the actual (raw) Message
as an argument. Again, no Message
will be sent back as all of these methods return void
. public interface RawMessageDelegate { void handleMessage(Message message); }This next example illustrates a
Message
delegate that just consumes the String
contents of {@link Message Messages}. Notice also how the name of the Message
handling method is different from the {@link #ORIGINAL_DEFAULT_LISTENER_METHOD original} (this will have to be configured in the attandant beandefinition). Again, no Message
will be sent back as the method returns void
. public interface TextMessageContentDelegate { void onMessage(String text); }This final example illustrates a
Message
delegate that just consumes the String
contents of {@link Message Messages}. Notice how the return type of this method is String
: This will result in the configured {@link MessageListenerAdapter} sending a {@link Message} in response.public interface ResponsiveTextMessageContentDelegate { String handleMessage(String text); }For further examples and discussion please do refer to the Spring reference documentation which describes this class (and its attendant XML configuration) in detail. @author Juergen Hoeller @author Mark Pollack @author Mark Fisher @author Dave Syer @author Gary Russell @author Greg Turnquist @see #setDelegate @see #setDefaultListenerMethod @see #setResponseRoutingKey(String) @see #setMessageConverter @see org.springframework.amqp.support.converter.SimpleMessageConverter @see org.springframework.amqp.rabbit.core.ChannelAwareMessageListener @see org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer#setMessageListener
By default, the content of incoming Redis messages gets extracted before being passed into the target listener method, to let the target method operate on message content types such as String or byte array instead of the raw {@link Message}. Message type conversion is delegated to a Spring Data {@link RedisSerializer}. By default, the {@link JdkSerializationRedisSerializer} will be used. (If you do not want such automatic message conversion takingplace, then be sure to set the {@link #setSerializer Serializer} to null
.)
Find below some examples of method signatures compliant with this adapter class. This first example handles all Message
types and gets passed the contents of each Message
type as an argument.
public interface MessageContentsDelegate { void handleMessage(String text); void handleMessage(byte[] bytes); void handleMessage(Person obj); }
In addition, the channel or pattern to which a message is sent can be passed in to the method as a second argument of type String:
public interface MessageContentsDelegate { void handleMessage(String text, String channel); void handleMessage(byte[] bytes, String pattern); }For further examples and discussion please do refer to the Spring Data reference documentation which describes this class (and its attendant configuration) in detail. Important: Due to the nature of messages, the default serializer used by the adapter is {@link StringRedisSerializer}. If the messages are of a different type, change them accordingly through {@link #setSerializer(RedisSerializer)}. @author Juergen Hoeller @author Costin Leau @author Greg Turnquist @author Thomas Darimont @author Christoph Strobl @see org.springframework.jms.listener.adapter.MessageListenerAdapter
NOTE: This class requires a JMS 1.1+ provider, because it builds on the domain-independent API. Use the {@link MessageListenerAdapter102 MessageListenerAdapter102} subclass for JMS 1.0.2 providers.
By default, the content of incoming JMS messages gets extracted before being passed into the target listener method, to let the target method operate on message content types such as String or byte array instead of the raw {@link Message}. Message type conversion is delegated to a Spring JMS {@link MessageConverter}. By default, a {@link SimpleMessageConverter}{@link org.springframework.jms.support.converter.SimpleMessageConverter102 (102)}will be used. (If you do not want such automatic message conversion taking place, then be sure to set the {@link #setMessageConverter MessageConverter}to null
.)
If a target listener method returns a non-null object (typically of a message content type such as String
or byte array), it will get wrapped in a JMS Message
and sent to the response destination (either the JMS "reply-to" destination or a {@link #setDefaultResponseDestination(javax.jms.Destination) specified defaultdestination}).
Note: The sending of response messages is only available when using the {@link SessionAwareMessageListener} entry point (typically through aSpring message listener container). Usage as standard JMS {@link MessageListener}does not support the generation of response messages.
Find below some examples of method signatures compliant with this adapter class. This first example handles all Message
types and gets passed the contents of each Message
type as an argument. No Message
will be sent back as all of these methods return void
.
public interface MessageContentsDelegate { void handleMessage(String text); void handleMessage(Map map); void handleMessage(byte[] bytes); void handleMessage(Serializable obj); }This next example handles all
Message
types and gets passed the actual (raw) Message
as an argument. Again, no Message
will be sent back as all of these methods return void
. public interface RawMessageDelegate { void handleMessage(TextMessage message); void handleMessage(MapMessage message); void handleMessage(BytesMessage message); void handleMessage(ObjectMessage message); }This next example illustrates a
Message
delegate that just consumes the String
contents of {@link javax.jms.TextMessage TextMessages}. Notice also how the name of the Message
handling method is different from the {@link #ORIGINAL_DEFAULT_LISTENER_METHOD original} (this will have tobe configured in the attandant bean definition). Again, no Message
will be sent back as the method returns void
. public interface TextMessageContentDelegate { void onMessage(String text); }This final example illustrates a
Message
delegate that just consumes the String
contents of {@link javax.jms.TextMessage TextMessages}. Notice how the return type of this method is String
: This will result in the configured {@link MessageListenerAdapter} sending a {@link javax.jms.TextMessage} in response.public interface ResponsiveTextMessageContentDelegate { String handleMessage(String text); }For further examples and discussion please do refer to the Spring reference documentation which describes this class (and it's attendant XML configuration) in detail. @author Juergen Hoeller @since 2.0 @see #setDelegate @see #setDefaultListenerMethod @see #setDefaultResponseDestination @see #setMessageConverter @see org.springframework.jms.support.converter.SimpleMessageConverter @see org.springframework.jms.listener.SessionAwareMessageListener @see org.springframework.jms.listener.AbstractMessageListenerContainer#setMessageListener
|
|