Revisit JmsMessagingTemplate

This commit revisits JmsMessagingTemplate and adds support for
receiving operations as well. JmsMessageSendingOperations has been
renamed to JmsMessageOperations.

The messaging abstraction did not split receiving and request-reply
operations. AbstractMessageReceivingTemplate has been created to hold
only the receiving operations.

Issue: SPR-11772
This commit is contained in:
Stephane Nicoll
2014-05-26 09:32:54 +02:00
parent 31c07dbfa4
commit 9fabcad3dd
7 changed files with 317 additions and 43 deletions

View File

@@ -0,0 +1,63 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.core;
import org.springframework.messaging.Message;
/**
* An extension of {@link AbstractMessageSendingTemplate} that adds support for
* receive style operations as defined by {@link MessageReceivingOperations}.
*
* @author Mark Fisher
* @author Rossen Stoyanchev
* @author Stephane Nicoll
* @since 4.1
*/
public abstract class AbstractMessageReceivingTemplate<D> extends AbstractMessageSendingTemplate<D>
implements MessageReceivingOperations<D> {
@Override
public Message<?> receive() {
return receive(getRequiredDefaultDestination());
}
@Override
public Message<?> receive(D destination) {
return doReceive(destination);
}
protected abstract Message<?> doReceive(D destination);
@Override
public <T> T receiveAndConvert(Class<T> targetClass) {
return receiveAndConvert(getRequiredDefaultDestination(), targetClass);
}
@SuppressWarnings("unchecked")
@Override
public <T> T receiveAndConvert(D destination, Class<T> targetClass) {
Message<?> message = doReceive(destination);
if (message != null) {
return (T) getMessageConverter().fromMessage(message, targetClass);
}
else {
return null;
}
}
}

View File

@@ -23,47 +23,15 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.MessageConversionException;
/**
* An extension of {@link AbstractMessageSendingTemplate} that adds support for
* receive as well as request-reply style operations as defined by
* {@link MessageReceivingOperations} and {@link MessageRequestReplyOperations}.
* An extension of {@link AbstractMessageReceivingTemplate} that adds support for
* request-reply style operations as defined by {@link MessageRequestReplyOperations}.
*
* @author Mark Fisher
* @author Rossen Stoyanchev
* @since 4.0
*/
public abstract class AbstractMessagingTemplate<D> extends AbstractMessageSendingTemplate<D>
implements MessageRequestReplyOperations<D>, MessageReceivingOperations<D> {
@Override
public Message<?> receive() {
return receive(getRequiredDefaultDestination());
}
@Override
public Message<?> receive(D destination) {
return doReceive(destination);
}
protected abstract Message<?> doReceive(D destination);
@Override
public <T> T receiveAndConvert(Class<T> targetClass) {
return receiveAndConvert(getRequiredDefaultDestination(), targetClass);
}
@SuppressWarnings("unchecked")
@Override
public <T> T receiveAndConvert(D destination, Class<T> targetClass) {
Message<?> message = doReceive(destination);
if (message != null) {
return (T) getMessageConverter().fromMessage(message, targetClass);
}
else {
return null;
}
}
public abstract class AbstractMessagingTemplate<D> extends AbstractMessageReceivingTemplate<D>
implements MessageRequestReplyOperations<D> {
@Override
public Message<?> sendAndReceive(Message<?> requestMessage) {