Browse Source
To improve compatibility between Spring's messaging classes and Spring Integration, the type of Message that is created has been made pluggable through the introduction of a factory abstraction; MessageFactory. By default a MessageFactory is provided that will create org.springframework.messaging.GenericMessage instances, however this can be replaced with an alternative implementation. For example, Spring Integration can provide an implementation that creates org.springframework.integration.message.GenericMessage instances. This control over the type of Message that's created allows messages to flow from Spring messaging code into Spring Integration code without any need for conversion. In further support of this goal, MessageChannel, MessageHandler, and SubscribableChannel have been genericized to make the Message type that they deal with more flexible.pull/286/merge
16 changed files with 188 additions and 51 deletions
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2013 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; |
||||
|
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* A {@link MessageFactory} that creates {@link GenericMessage GenericMessages}. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public class GenericMessageFactory implements MessageFactory<GenericMessage<?>> { |
||||
|
||||
@Override |
||||
public <P> GenericMessage<?> createMessage(P payload, Map<String, Object> headers) { |
||||
return new GenericMessage<P>(payload, headers); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2002-2013 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; |
||||
|
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* A factory for creating messages, allowing for control of the concrete type of the message. |
||||
* |
||||
* |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public interface MessageFactory<M extends Message<?>> { |
||||
|
||||
/** |
||||
* Creates a new message with the given payload and headers |
||||
* |
||||
* @param payload The message payload |
||||
* @param headers The message headers |
||||
* @param <P> The payload's type |
||||
* |
||||
* @return the message |
||||
*/ |
||||
<P> M createMessage(P payload, Map<String, Object> headers); |
||||
} |
||||
Loading…
Reference in new issue