Add MessageSendingOperations for JMS

This commit adds a JMS implementation of MessageSendingOperations,
allowing to send JMS messages using Spring's standard Messaging
abstraction.

MessagingMessageConverter is a standard JMS's MessageConverter that
can convert Spring's Message to JMS message and vice versa. Existing
infrastructure has been updated to use this implementation.

Issue: SPR-11772
This commit is contained in:
Stephane Nicoll
2014-05-19 10:42:18 +02:00
parent 82336c320d
commit 7469159bf1
11 changed files with 831 additions and 27 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.util.Assert;
*
* @author Mark Fisher
* @author Rossen Stoyanchev
* @author Stephane Nicoll
* @since 4.0
*/
public abstract class AbstractMessageSendingTemplate<D> implements MessageSendingOperations<D> {
@@ -99,7 +100,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
@Override
public void convertAndSend(Object payload) throws MessagingException {
convertAndSend(getRequiredDefaultDestination(), payload);
convertAndSend(payload, null);
}
@Override
@@ -128,6 +129,20 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
public void convertAndSend(D destination, Object payload, Map<String, Object> headers,
MessagePostProcessor postProcessor) throws MessagingException {
Message<?> message = doConvert(payload, headers, postProcessor);
send(destination, message);
}
/**
* Convert the given Object to serialized form, possibly using a
* {@link MessageConverter}, wrap it as a message with the given
* headers and apply the given post processor.
* @param payload the Object to use as payload
* @param headers headers for the message to send
* @param postProcessor the post processor to apply to the message
* @return the converted message
*/
protected Message<?> doConvert(Object payload, Map<String, Object> headers, MessagePostProcessor postProcessor) {
MessageHeaders messageHeaders = null;
Map<String, Object> headersToUse = processHeadersToSend(headers);
if (headersToUse != null) {
@@ -149,7 +164,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
if (postProcessor != null) {
message = postProcessor.postProcessMessage(message);
}
send(destination, message);
return message;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ public interface MessageSendingOperations<D> {
* Convert the given Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
* wrap it as a message with the given headers and send it to
* a default destination.
* the given destination.
* @param destination the target destination
* @param payload the Object to use as payload
* @param headers headers for the message to send