Added channel reference to Subscription and refactored/simplified TargetAdapter (implements MessageHandler).
This commit is contained in:
@@ -19,12 +19,10 @@ package org.springframework.integration.adapter;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
import org.springframework.integration.message.MessageMapper;
|
import org.springframework.integration.message.MessageMapper;
|
||||||
import org.springframework.integration.message.SimplePayloadMessageMapper;
|
import org.springframework.integration.message.SimplePayloadMessageMapper;
|
||||||
import org.springframework.integration.scheduling.PollingSchedule;
|
|
||||||
import org.springframework.integration.scheduling.Schedule;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,35 +30,12 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractTargetAdapter<T> implements TargetAdapter {
|
public abstract class AbstractTargetAdapter<T> implements MessageHandler {
|
||||||
|
|
||||||
protected Log logger = LogFactory.getLog(this.getClass());
|
protected Log logger = LogFactory.getLog(this.getClass());
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private MessageChannel channel;
|
|
||||||
|
|
||||||
private MessageMapper<?,T> mapper = new SimplePayloadMessageMapper<T>();
|
private MessageMapper<?,T> mapper = new SimplePayloadMessageMapper<T>();
|
||||||
|
|
||||||
private Schedule schedule = new PollingSchedule(5);
|
|
||||||
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChannel(MessageChannel channel) {
|
|
||||||
Assert.notNull(channel, "'channel' must not be null");
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageChannel getChannel() {
|
|
||||||
return this.channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageMapper(MessageMapper<?,T> mapper) {
|
public void setMessageMapper(MessageMapper<?,T> mapper) {
|
||||||
Assert.notNull(mapper, "'mapper' must not be null");
|
Assert.notNull(mapper, "'mapper' must not be null");
|
||||||
@@ -71,15 +46,6 @@ public abstract class AbstractTargetAdapter<T> implements TargetAdapter {
|
|||||||
return this.mapper;
|
return this.mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchedule(Schedule schedule) {
|
|
||||||
Assert.notNull(schedule, "'schedule' must not be null");
|
|
||||||
this.schedule = schedule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Schedule getSchedule() {
|
|
||||||
return this.schedule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Message handle(Message message) {
|
public final Message handle(Message message) {
|
||||||
this.sendToTarget(this.mapper.fromMessage(message));
|
this.sendToTarget(this.mapper.fromMessage(message));
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2002-2007 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.integration.adapter;
|
|
||||||
|
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
|
||||||
import org.springframework.integration.handler.MessageHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base interface for target adapters.
|
|
||||||
*
|
|
||||||
* @author Mark Fisher
|
|
||||||
*/
|
|
||||||
public interface TargetAdapter extends MessageHandler {
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
void setChannel(MessageChannel channel);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -28,11 +28,11 @@ import org.springframework.beans.BeansException;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.context.Lifecycle;
|
import org.springframework.context.Lifecycle;
|
||||||
|
import org.springframework.integration.MessagingConfigurationException;
|
||||||
import org.springframework.integration.MessagingException;
|
import org.springframework.integration.MessagingException;
|
||||||
import org.springframework.integration.adapter.AbstractTargetAdapter;
|
|
||||||
import org.springframework.integration.adapter.SourceAdapter;
|
import org.springframework.integration.adapter.SourceAdapter;
|
||||||
import org.springframework.integration.adapter.TargetAdapter;
|
|
||||||
import org.springframework.integration.channel.ChannelRegistry;
|
import org.springframework.integration.channel.ChannelRegistry;
|
||||||
|
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||||
import org.springframework.integration.channel.DefaultChannelRegistry;
|
import org.springframework.integration.channel.DefaultChannelRegistry;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
@@ -40,6 +40,7 @@ import org.springframework.integration.dispatcher.DefaultMessageDispatcher;
|
|||||||
import org.springframework.integration.dispatcher.DispatcherPolicy;
|
import org.springframework.integration.dispatcher.DispatcherPolicy;
|
||||||
import org.springframework.integration.dispatcher.MessageDispatcher;
|
import org.springframework.integration.dispatcher.MessageDispatcher;
|
||||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
||||||
|
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||||
import org.springframework.integration.handler.MessageHandler;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.handler.PooledMessageHandler;
|
import org.springframework.integration.handler.PooledMessageHandler;
|
||||||
@@ -50,7 +51,6 @@ import org.springframework.integration.scheduling.Schedule;
|
|||||||
import org.springframework.integration.scheduling.SimpleMessagingTaskScheduler;
|
import org.springframework.integration.scheduling.SimpleMessagingTaskScheduler;
|
||||||
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The messaging bus. Serves as a registry for channels and endpoints, manages their lifecycle,
|
* The messaging bus. Serves as a registry for channels and endpoints, manages their lifecycle,
|
||||||
@@ -64,7 +64,7 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
|
|||||||
|
|
||||||
private ChannelRegistry channelRegistry = new DefaultChannelRegistry();
|
private ChannelRegistry channelRegistry = new DefaultChannelRegistry();
|
||||||
|
|
||||||
private Map<String, MessageHandler> handlers = new ConcurrentHashMap<String, MessageHandler>();
|
private Map<String, MessageEndpoint> endpoints = new ConcurrentHashMap<String, MessageEndpoint>();
|
||||||
|
|
||||||
private Map<MessageChannel, MessageDispatcher> dispatchers = new ConcurrentHashMap<MessageChannel, MessageDispatcher>();
|
private Map<MessageChannel, MessageDispatcher> dispatchers = new ConcurrentHashMap<MessageChannel, MessageDispatcher>();
|
||||||
|
|
||||||
@@ -90,8 +90,6 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
|
|||||||
this.registerChannels(applicationContext);
|
this.registerChannels(applicationContext);
|
||||||
this.registerEndpoints(applicationContext);
|
this.registerEndpoints(applicationContext);
|
||||||
this.registerSourceAdapters(applicationContext);
|
this.registerSourceAdapters(applicationContext);
|
||||||
this.registerTargetAdapters(applicationContext);
|
|
||||||
this.activateSubscriptions(applicationContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,28 +138,6 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void registerTargetAdapters(ApplicationContext context) {
|
|
||||||
Map<String, TargetAdapter> targetAdapterBeans =
|
|
||||||
(Map<String, TargetAdapter>) context.getBeansOfType(TargetAdapter.class);
|
|
||||||
for (Map.Entry<String, TargetAdapter> entry : targetAdapterBeans.entrySet()) {
|
|
||||||
this.registerTargetAdapter(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void activateSubscriptions(ApplicationContext context) {
|
|
||||||
Map<String, Subscription> subscriptionBeans =
|
|
||||||
(Map<String, Subscription>) context.getBeansOfType(Subscription.class);
|
|
||||||
for (Subscription subscription : subscriptionBeans.values()) {
|
|
||||||
this.activateSubscription(subscription);
|
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("activated subscription to channel '" + subscription.getChannel() +
|
|
||||||
"' for handler '" + subscription.getHandler() + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
if (this.getInvalidMessageChannel() == null) {
|
if (this.getInvalidMessageChannel() == null) {
|
||||||
this.setInvalidMessageChannel(new SimpleChannel(Integer.MAX_VALUE));
|
this.setInvalidMessageChannel(new SimpleChannel(Integer.MAX_VALUE));
|
||||||
@@ -212,32 +188,72 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
|
|||||||
}
|
}
|
||||||
this.dispatchers.put(channel, dispatcher);
|
this.dispatchers.put(channel, dispatcher);
|
||||||
this.channelRegistry.registerChannel(name, channel);
|
this.channelRegistry.registerChannel(name, channel);
|
||||||
|
if (logger.isInfoEnabled()) {
|
||||||
|
logger.info("registered channel '" + name + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEndpoint(String name, MessageEndpoint endpoint) {
|
public void registerHandler(String name, MessageHandler handler, Subscription subscription) {
|
||||||
|
this.registerHandler(name, handler, subscription, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerHandler(String name, MessageHandler handler, Subscription subscription, ConcurrencyPolicy concurrencyPolicy) {
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
this.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
Assert.notNull(name, "'name' must not be null");
|
Assert.notNull(name, "'name' must not be null");
|
||||||
Assert.notNull(endpoint, "'endpoint' must not be null");
|
Assert.notNull(handler, "'handler' must not be null");
|
||||||
|
Assert.notNull(subscription, "'subscription' must not be null");
|
||||||
|
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
||||||
endpoint.setName(name);
|
endpoint.setName(name);
|
||||||
this.handlers.put(name, endpoint);
|
endpoint.setHandler(handler);
|
||||||
endpoint.setChannelRegistry(this);
|
endpoint.setSubscription(subscription);
|
||||||
Schedule schedule = endpoint.getSchedule();
|
endpoint.setConcurrencyPolicy(concurrencyPolicy);
|
||||||
if (endpoint.getInputChannelName() != null) {
|
this.registerEndpoint(name, endpoint);
|
||||||
Subscription subscription = new Subscription();
|
}
|
||||||
subscription.setHandler(name);
|
|
||||||
subscription.setChannel(endpoint.getInputChannelName());
|
public void registerEndpoint(String name, MessageEndpoint endpoint) {
|
||||||
if (schedule != null) {
|
if (endpoint instanceof ChannelRegistryAware) {
|
||||||
subscription.setSchedule(schedule);
|
((ChannelRegistryAware) endpoint).setChannelRegistry(this.channelRegistry);
|
||||||
}
|
|
||||||
this.activateSubscription(subscription);
|
|
||||||
}
|
}
|
||||||
if (this.autoCreateChannels) {
|
this.endpoints.put(name, endpoint);
|
||||||
String defaultOutputChannelName = endpoint.getDefaultOutputChannelName();
|
if (logger.isInfoEnabled()) {
|
||||||
if (StringUtils.hasText(defaultOutputChannelName) && this.lookupChannel(defaultOutputChannelName) == null) {
|
logger.info("registered endpoint '" + name + "'");
|
||||||
this.registerChannel(defaultOutputChannelName, new SimpleChannel());
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void activateEndpoints() {
|
||||||
|
for (MessageEndpoint endpoint : this.endpoints.values()) {
|
||||||
|
this.activateEndpoint(endpoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void activateEndpoint(MessageEndpoint endpoint) {
|
||||||
|
Subscription subscription = endpoint.getSubscription();
|
||||||
|
MessageChannel channel = subscription.getChannel();
|
||||||
|
if (channel == null) {
|
||||||
|
String channelName = subscription.getChannelName();
|
||||||
|
if (channelName == null) {
|
||||||
|
throw new MessagingConfigurationException("endpoint '" + endpoint.getName() +
|
||||||
|
"' must provide either 'channel' or 'channelName' in its subscription metadata");
|
||||||
}
|
}
|
||||||
|
channel = this.lookupChannel(channelName);
|
||||||
|
if (channel == null) {
|
||||||
|
if (this.autoCreateChannels == false) {
|
||||||
|
throw new MessagingException("Cannot activate subscription, unknown channel '" + channelName +
|
||||||
|
"'. Consider enabling the 'autoCreateChannels' option for the message bus.");
|
||||||
|
}
|
||||||
|
if (this.logger.isInfoEnabled()) {
|
||||||
|
logger.info("auto-creating channel '" + channel.getName() + "'");
|
||||||
|
}
|
||||||
|
channel = new SimpleChannel();
|
||||||
|
this.registerChannel(channelName, channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.registerWithDispatcher(channel, endpoint, subscription.getSchedule(), endpoint.getConcurrencyPolicy());
|
||||||
|
if (logger.isInfoEnabled()) {
|
||||||
|
logger.info("activated subscription to channel '" + channel.getName() +
|
||||||
|
"' for endpoint '" + endpoint.getName() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,56 +275,11 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerTargetAdapter(String name, TargetAdapter targetAdapter) {
|
private void registerWithDispatcher(MessageChannel channel, MessageHandler handler, Schedule schedule, ConcurrencyPolicy concurrencyPolicy) {
|
||||||
if (targetAdapter instanceof AbstractTargetAdapter) {
|
|
||||||
AbstractTargetAdapter<?> adapter = (AbstractTargetAdapter<?>) targetAdapter;
|
|
||||||
adapter.setName(name);
|
|
||||||
this.handlers.put(name, adapter);
|
|
||||||
MessageChannel channel = adapter.getChannel();
|
|
||||||
Schedule schedule = adapter.getSchedule();
|
|
||||||
ConcurrencyPolicy concurrencyPolicy = new ConcurrencyPolicy();
|
|
||||||
concurrencyPolicy.setCoreConcurrency(1);
|
|
||||||
concurrencyPolicy.setMaxConcurrency(1);
|
|
||||||
this.doActivate(channel, adapter, schedule, concurrencyPolicy);
|
|
||||||
}
|
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("registered target adapter '" + name + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activateSubscription(Subscription subscription) {
|
|
||||||
String channelName = subscription.getChannel();
|
|
||||||
String handlerName = subscription.getHandler();
|
|
||||||
Schedule schedule = subscription.getSchedule();
|
|
||||||
ConcurrencyPolicy concurrencyPolicy = subscription.getConcurrencyPolicy();
|
|
||||||
MessageHandler handler = this.handlers.get(handlerName);
|
|
||||||
if (handler == null) {
|
|
||||||
throw new MessagingException("Cannot activate subscription, unknown handler '" + handlerName + "'");
|
|
||||||
}
|
|
||||||
MessageChannel channel = this.lookupChannel(channelName);
|
|
||||||
if (channel == null) {
|
|
||||||
if (this.autoCreateChannels == false) {
|
|
||||||
throw new MessagingException("Cannot activate subscription, unknown channel '" + channelName +
|
|
||||||
"'. Consider enabling the 'autoCreateChannels' option for the message bus.");
|
|
||||||
}
|
|
||||||
if (this.logger.isInfoEnabled()) {
|
|
||||||
logger.info("auto-creating channel '" + channelName + "'");
|
|
||||||
}
|
|
||||||
channel = new SimpleChannel();
|
|
||||||
this.registerChannel(channelName, channel);
|
|
||||||
}
|
|
||||||
this.doActivate(channel, handler, schedule, concurrencyPolicy);
|
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("activated subscription to channel '" + channelName +
|
|
||||||
"' for handler '" + handlerName + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doActivate(MessageChannel channel, MessageHandler handler, Schedule schedule, ConcurrencyPolicy concurrencyPolicy) {
|
|
||||||
MessageDispatcher dispatcher = dispatchers.get(channel);
|
MessageDispatcher dispatcher = dispatchers.get(channel);
|
||||||
if (dispatcher == null) {
|
if (dispatcher == null) {
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("no dispatcher available for channel '" + channel + "', be sure to register the channel");
|
logger.warn("no dispatcher available for channel '" + channel.getName() + "', be sure to register the channel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (concurrencyPolicy != null) {
|
if (concurrencyPolicy != null) {
|
||||||
@@ -335,8 +306,8 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
|
|||||||
}
|
}
|
||||||
this.starting = true;
|
this.starting = true;
|
||||||
synchronized (this.lifecycleMonitor) {
|
synchronized (this.lifecycleMonitor) {
|
||||||
|
this.activateEndpoints();
|
||||||
this.taskScheduler.start();
|
this.taskScheduler.start();
|
||||||
this.running = true;
|
|
||||||
for (MessageDispatcher dispatcher : this.dispatchers.values()) {
|
for (MessageDispatcher dispatcher : this.dispatchers.values()) {
|
||||||
dispatcher.start();
|
dispatcher.start();
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.integration.bus;
|
package org.springframework.integration.bus;
|
||||||
|
|
||||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.scheduling.Schedule;
|
import org.springframework.integration.scheduling.Schedule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,29 +26,39 @@ import org.springframework.integration.scheduling.Schedule;
|
|||||||
*/
|
*/
|
||||||
public class Subscription {
|
public class Subscription {
|
||||||
|
|
||||||
private String channel;
|
private MessageChannel channel;
|
||||||
|
|
||||||
private String handler;
|
private String channelName;
|
||||||
|
|
||||||
private Schedule schedule;
|
private Schedule schedule;
|
||||||
|
|
||||||
private ConcurrencyPolicy concurrencyPolicy;
|
|
||||||
|
|
||||||
|
public Subscription() {
|
||||||
public String getChannel() {
|
|
||||||
return this.channel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(String channel) {
|
public Subscription(MessageChannel channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHandler() {
|
public Subscription(String channelName) {
|
||||||
return this.handler;
|
this.channelName = channelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHandler(String handler) {
|
|
||||||
this.handler = handler;
|
public MessageChannel getChannel() {
|
||||||
|
return this.channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannel(MessageChannel channel) {
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChannelName() {
|
||||||
|
return (this.channel != null) ? this.channel.getName() : this.channelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannelName(String channelName) {
|
||||||
|
this.channelName = channelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Schedule getSchedule() {
|
public Schedule getSchedule() {
|
||||||
@@ -59,12 +69,4 @@ public class Subscription {
|
|||||||
this.schedule = schedule;
|
this.schedule = schedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrencyPolicy getConcurrencyPolicy() {
|
|
||||||
return this.concurrencyPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConcurrencyPolicy(ConcurrencyPolicy concurrencyPolicy) {
|
|
||||||
this.concurrencyPolicy = concurrencyPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ package org.springframework.integration.channel;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,8 +28,6 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class DefaultChannelRegistry implements ChannelRegistry {
|
public class DefaultChannelRegistry implements ChannelRegistry {
|
||||||
|
|
||||||
private Log logger = LogFactory.getLog(this.getClass());
|
|
||||||
|
|
||||||
private Map<String, MessageChannel> channels = new ConcurrentHashMap<String, MessageChannel>();
|
private Map<String, MessageChannel> channels = new ConcurrentHashMap<String, MessageChannel>();
|
||||||
|
|
||||||
private MessageChannel invalidMessageChannel;
|
private MessageChannel invalidMessageChannel;
|
||||||
@@ -55,9 +50,6 @@ public class DefaultChannelRegistry implements ChannelRegistry {
|
|||||||
Assert.notNull(channel, "'channel' must not be null");
|
Assert.notNull(channel, "'channel' must not be null");
|
||||||
channel.setName(name);
|
channel.setName(name);
|
||||||
this.channels.put(name, channel);
|
this.channels.put(name, channel);
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("registered channel '" + name + "'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import org.springframework.integration.adapter.DefaultTargetAdapter;
|
|||||||
import org.springframework.integration.adapter.MethodInvokingSource;
|
import org.springframework.integration.adapter.MethodInvokingSource;
|
||||||
import org.springframework.integration.adapter.MethodInvokingTarget;
|
import org.springframework.integration.adapter.MethodInvokingTarget;
|
||||||
import org.springframework.integration.adapter.PollingSourceAdapter;
|
import org.springframework.integration.adapter.PollingSourceAdapter;
|
||||||
|
import org.springframework.integration.bus.Subscription;
|
||||||
|
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,6 +81,7 @@ public class ChannelAdapterParser implements BeanDefinitionParser {
|
|||||||
if (StringUtils.hasText(period)) {
|
if (StringUtils.hasText(period)) {
|
||||||
adapterDef.getPropertyValues().addPropertyValue("period", period);
|
adapterDef.getPropertyValues().addPropertyValue("period", period);
|
||||||
}
|
}
|
||||||
|
adapterDef.getPropertyValues().addPropertyValue("channel", new RuntimeBeanReference(channel));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
adapterDef = new RootBeanDefinition(DefaultTargetAdapter.class);
|
adapterDef = new RootBeanDefinition(DefaultTargetAdapter.class);
|
||||||
@@ -89,12 +92,22 @@ public class ChannelAdapterParser implements BeanDefinitionParser {
|
|||||||
String invokerBeanName = parserContext.getReaderContext().generateBeanName(invokerDef);
|
String invokerBeanName = parserContext.getReaderContext().generateBeanName(invokerDef);
|
||||||
parserContext.registerBeanComponent(new BeanComponentDefinition(invokerDef, invokerBeanName));
|
parserContext.registerBeanComponent(new BeanComponentDefinition(invokerDef, invokerBeanName));
|
||||||
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(invokerBeanName));
|
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(invokerBeanName));
|
||||||
adapterDef.getPropertyValues().addPropertyValue("channel", new RuntimeBeanReference(channel));
|
|
||||||
adapterDef.setSource(parserContext.extractSource(element));
|
adapterDef.setSource(parserContext.extractSource(element));
|
||||||
String beanName = element.getAttribute(ID_ATTRIBUTE);
|
String beanName = element.getAttribute(ID_ATTRIBUTE);
|
||||||
if (!StringUtils.hasText(beanName)) {
|
if (!StringUtils.hasText(beanName)) {
|
||||||
beanName = parserContext.getReaderContext().generateBeanName(adapterDef);
|
beanName = parserContext.getReaderContext().generateBeanName(adapterDef);
|
||||||
}
|
}
|
||||||
|
if (!this.isInbound) {
|
||||||
|
RootBeanDefinition endpointDef = new RootBeanDefinition(DefaultMessageEndpoint.class);
|
||||||
|
RootBeanDefinition subscriptionDef = new RootBeanDefinition(Subscription.class);
|
||||||
|
subscriptionDef.getPropertyValues().addPropertyValue("channel", new RuntimeBeanReference(channel));
|
||||||
|
String subscriptionBeanName = parserContext.getReaderContext().generateBeanName(subscriptionDef);
|
||||||
|
parserContext.registerBeanComponent(new BeanComponentDefinition(subscriptionDef, subscriptionBeanName));
|
||||||
|
endpointDef.getPropertyValues().addPropertyValue("subscription", new RuntimeBeanReference(subscriptionBeanName));
|
||||||
|
endpointDef.getPropertyValues().addPropertyValue("handler", new RuntimeBeanReference(beanName));
|
||||||
|
String endpointBeanName = parserContext.getReaderContext().generateBeanName(endpointDef);
|
||||||
|
parserContext.registerBeanComponent(new BeanComponentDefinition(endpointDef, endpointBeanName));
|
||||||
|
}
|
||||||
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, beanName));
|
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, beanName));
|
||||||
return adapterDef;
|
return adapterDef;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
|||||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.integration.MessagingConfigurationException;
|
import org.springframework.integration.MessagingConfigurationException;
|
||||||
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||||
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
|
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
|
||||||
@@ -49,7 +50,9 @@ public class EndpointParser implements BeanDefinitionParser {
|
|||||||
|
|
||||||
private static final String INPUT_CHANNEL_ATTRIBUTE = "input-channel";
|
private static final String INPUT_CHANNEL_ATTRIBUTE = "input-channel";
|
||||||
|
|
||||||
private static final String INPUT_CHANNEL_PROPERTY = "inputChannelName";
|
private static final String SUBSCRIPTION_PROPERTY = "subscription";
|
||||||
|
|
||||||
|
private static final String CHANNEL_PROPERTY = "channel";
|
||||||
|
|
||||||
private static final String DEFAULT_OUTPUT_CHANNEL_ATTRIBUTE = "default-output-channel";
|
private static final String DEFAULT_OUTPUT_CHANNEL_ATTRIBUTE = "default-output-channel";
|
||||||
|
|
||||||
@@ -90,8 +93,9 @@ public class EndpointParser implements BeanDefinitionParser {
|
|||||||
RootBeanDefinition endpointDef = new RootBeanDefinition(DefaultMessageEndpoint.class);
|
RootBeanDefinition endpointDef = new RootBeanDefinition(DefaultMessageEndpoint.class);
|
||||||
endpointDef.setSource(parserContext.extractSource(element));
|
endpointDef.setSource(parserContext.extractSource(element));
|
||||||
String inputChannel = element.getAttribute(INPUT_CHANNEL_ATTRIBUTE);
|
String inputChannel = element.getAttribute(INPUT_CHANNEL_ATTRIBUTE);
|
||||||
|
RootBeanDefinition subscriptionDef = new RootBeanDefinition(Subscription.class);
|
||||||
if (StringUtils.hasText(inputChannel)) {
|
if (StringUtils.hasText(inputChannel)) {
|
||||||
endpointDef.getPropertyValues().addPropertyValue(INPUT_CHANNEL_PROPERTY, inputChannel);
|
subscriptionDef.getPropertyValues().addPropertyValue(CHANNEL_PROPERTY, new RuntimeBeanReference(inputChannel));
|
||||||
}
|
}
|
||||||
String defaultOutputChannel = element.getAttribute(DEFAULT_OUTPUT_CHANNEL_ATTRIBUTE);
|
String defaultOutputChannel = element.getAttribute(DEFAULT_OUTPUT_CHANNEL_ATTRIBUTE);
|
||||||
if (StringUtils.hasText(defaultOutputChannel)) {
|
if (StringUtils.hasText(defaultOutputChannel)) {
|
||||||
@@ -104,7 +108,7 @@ public class EndpointParser implements BeanDefinitionParser {
|
|||||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
String localName = child.getLocalName();
|
String localName = child.getLocalName();
|
||||||
if (CONCURRENCY_ELEMENT.equals(localName)) {
|
if (CONCURRENCY_ELEMENT.equals(localName)) {
|
||||||
parseConcurrencyPolicy((Element) child, endpointDef);
|
parseConcurrencyPolicy((Element) child, subscriptionDef);
|
||||||
}
|
}
|
||||||
else if (HANDLER_ELEMENT.equals(localName)) {
|
else if (HANDLER_ELEMENT.equals(localName)) {
|
||||||
String ref = ((Element) child).getAttribute(REF_ATTRIBUTE);
|
String ref = ((Element) child).getAttribute(REF_ATTRIBUTE);
|
||||||
@@ -113,6 +117,9 @@ public class EndpointParser implements BeanDefinitionParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String subscriptionBeanName = parserContext.getReaderContext().generateBeanName(subscriptionDef);
|
||||||
|
parserContext.registerBeanComponent(new BeanComponentDefinition(subscriptionDef, subscriptionBeanName));
|
||||||
|
endpointDef.getPropertyValues().addPropertyValue(SUBSCRIPTION_PROPERTY, new RuntimeBeanReference(subscriptionBeanName));
|
||||||
if (childHandlerRefs.size() > 0) {
|
if (childHandlerRefs.size() > 0) {
|
||||||
if (childHandlerRefs.size() == 1) {
|
if (childHandlerRefs.size() == 1) {
|
||||||
endpointDef.getPropertyValues().addPropertyValue(
|
endpointDef.getPropertyValues().addPropertyValue(
|
||||||
@@ -153,7 +160,7 @@ public class EndpointParser implements BeanDefinitionParser {
|
|||||||
return endpointDef;
|
return endpointDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseConcurrencyPolicy(Element concurrencyElement, RootBeanDefinition endpointDefinition) {
|
private void parseConcurrencyPolicy(Element concurrencyElement, RootBeanDefinition subscriptionDefinition) {
|
||||||
ConcurrencyPolicy policy = new ConcurrencyPolicy();
|
ConcurrencyPolicy policy = new ConcurrencyPolicy();
|
||||||
String coreConcurrency = concurrencyElement.getAttribute(CORE_CONCURRENCY_ATTRIBUTE);
|
String coreConcurrency = concurrencyElement.getAttribute(CORE_CONCURRENCY_ATTRIBUTE);
|
||||||
String maxConcurrency = concurrencyElement.getAttribute(MAX_CONCURRENCY_ATTRIBUTE);
|
String maxConcurrency = concurrencyElement.getAttribute(MAX_CONCURRENCY_ATTRIBUTE);
|
||||||
@@ -163,7 +170,7 @@ public class EndpointParser implements BeanDefinitionParser {
|
|||||||
if (StringUtils.hasText(maxConcurrency)) {
|
if (StringUtils.hasText(maxConcurrency)) {
|
||||||
policy.setMaxConcurrency(Integer.parseInt(maxConcurrency));
|
policy.setMaxConcurrency(Integer.parseInt(maxConcurrency));
|
||||||
}
|
}
|
||||||
endpointDefinition.getPropertyValues().addPropertyValue(CONCURRENCY_POLICY_PROPERTY, policy);
|
subscriptionDefinition.getPropertyValues().addPropertyValue(CONCURRENCY_POLICY_PROPERTY, policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseSchedule(Element scheduleElement, RootBeanDefinition endpointDefinition) {
|
private void parseSchedule(Element scheduleElement, RootBeanDefinition endpointDefinition) {
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ import org.springframework.integration.annotation.Polled;
|
|||||||
import org.springframework.integration.annotation.Router;
|
import org.springframework.integration.annotation.Router;
|
||||||
import org.springframework.integration.annotation.Splitter;
|
import org.springframework.integration.annotation.Splitter;
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.channel.ChannelRegistryAware;
|
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||||
import org.springframework.integration.handler.MessageHandler;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.handler.MessageHandlerChain;
|
import org.springframework.integration.handler.MessageHandlerChain;
|
||||||
@@ -106,24 +106,23 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
|
|||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
||||||
this.configureInputChannel(bean, beanName, endpointAnnotation, endpoint);
|
this.configureInput(bean, beanName, endpointAnnotation, endpoint);
|
||||||
this.configureDefaultOutputChannel(bean, beanName, endpointAnnotation, endpoint);
|
|
||||||
MessageHandlerChain handlerChain = this.createHandlerChain(bean);
|
MessageHandlerChain handlerChain = this.createHandlerChain(bean);
|
||||||
if (handlerChain != null) {
|
endpoint.setHandler(handlerChain);
|
||||||
endpoint.setHandler(handlerChain);
|
this.configureDefaultOutput(bean, beanName, endpointAnnotation, endpoint);
|
||||||
}
|
this.messageBus.registerEndpoint(bean + "-endpoint", endpoint);
|
||||||
this.messageBus.registerEndpoint(beanName, endpoint);
|
return bean;
|
||||||
return endpoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureInputChannel(final Object bean, final String beanName,
|
private void configureInput(final Object bean, final String beanName, MessageEndpoint annotation,
|
||||||
MessageEndpoint annotation, final DefaultMessageEndpoint endpoint) {
|
final DefaultMessageEndpoint endpoint) {
|
||||||
String channelName = annotation.input();
|
String channelName = annotation.input();
|
||||||
if (StringUtils.hasText(channelName)) {
|
if (StringUtils.hasText(channelName)) {
|
||||||
endpoint.setInputChannelName(channelName);
|
Subscription subscription = new Subscription();
|
||||||
|
subscription.setChannelName(channelName);
|
||||||
Schedule schedule = new PollingSchedule(annotation.pollPeriod());
|
Schedule schedule = new PollingSchedule(annotation.pollPeriod());
|
||||||
endpoint.setSchedule(schedule);
|
subscription.setSchedule(schedule);
|
||||||
return;
|
endpoint.setSubscription(subscription);
|
||||||
}
|
}
|
||||||
ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback() {
|
ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback() {
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||||
@@ -140,22 +139,16 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
|
|||||||
String channelName = beanName + "-inputChannel";
|
String channelName = beanName + "-inputChannel";
|
||||||
messageBus.registerChannel(channelName, channel);
|
messageBus.registerChannel(channelName, channel);
|
||||||
messageBus.registerSourceAdapter(beanName + "-sourceAdapter", adapter);
|
messageBus.registerSourceAdapter(beanName + "-sourceAdapter", adapter);
|
||||||
endpoint.setInputChannelName(channelName);
|
Subscription subscription = new Subscription(channel);
|
||||||
Schedule schedule = new PollingSchedule(period);
|
Schedule schedule = new PollingSchedule(period);
|
||||||
endpoint.setSchedule(schedule);
|
subscription.setSchedule(schedule);
|
||||||
if (period > 0) {
|
endpoint.setSubscription(subscription);
|
||||||
ConcurrencyPolicy concurrencyPolicy = new ConcurrencyPolicy();
|
|
||||||
concurrencyPolicy.setCoreConcurrency(1);
|
|
||||||
concurrencyPolicy.setMaxConcurrency(1);
|
|
||||||
endpoint.setConcurrencyPolicy(concurrencyPolicy);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureDefaultOutputChannel(final Object bean, final String beanName,
|
private void configureDefaultOutput(final Object bean, final String beanName,
|
||||||
final MessageEndpoint annotation, final DefaultMessageEndpoint endpoint) {
|
final MessageEndpoint annotation, final DefaultMessageEndpoint endpoint) {
|
||||||
String channelName = annotation.defaultOutput();
|
String channelName = annotation.defaultOutput();
|
||||||
if (StringUtils.hasText(channelName)) {
|
if (StringUtils.hasText(channelName)) {
|
||||||
@@ -177,8 +170,9 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
|
|||||||
DefaultTargetAdapter adapter = new DefaultTargetAdapter(target);
|
DefaultTargetAdapter adapter = new DefaultTargetAdapter(target);
|
||||||
SimpleChannel channel = new SimpleChannel();
|
SimpleChannel channel = new SimpleChannel();
|
||||||
String channelName = beanName + "-defaultOutputChannel";
|
String channelName = beanName + "-defaultOutputChannel";
|
||||||
|
Subscription subscription = new Subscription(channel);
|
||||||
messageBus.registerChannel(channelName, channel);
|
messageBus.registerChannel(channelName, channel);
|
||||||
messageBus.registerTargetAdapter(beanName + "-targetAdapter", adapter);
|
messageBus.registerHandler(beanName + "-targetAdapter", adapter, subscription);
|
||||||
endpoint.setDefaultOutputChannelName(channelName);
|
endpoint.setDefaultOutputChannelName(channelName);
|
||||||
foundDefaultOutput = true;
|
foundDefaultOutput = true;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
|
|||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.integration.annotation.Subscriber;
|
import org.springframework.integration.annotation.Subscriber;
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
|
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
@@ -85,13 +85,10 @@ public class SubscriberAnnotationPostProcessor implements BeanPostProcessor {
|
|||||||
adapter.setMethodName(method.getName());
|
adapter.setMethodName(method.getName());
|
||||||
adapter.setObject(bean);
|
adapter.setObject(bean);
|
||||||
adapter.afterPropertiesSet();
|
adapter.afterPropertiesSet();
|
||||||
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
String adapterName = ClassUtils.getShortNameAsProperty(targetClass) +
|
||||||
endpoint.setInputChannelName(channelName);
|
|
||||||
endpoint.setChannelRegistry(messageBus);
|
|
||||||
endpoint.setHandler(adapter);
|
|
||||||
String endpointName = ClassUtils.getShortNameAsProperty(targetClass) +
|
|
||||||
"-" + method.getName() + "-endpoint";
|
"-" + method.getName() + "-endpoint";
|
||||||
messageBus.registerEndpoint(endpointName, endpoint);
|
Subscription subscription = new Subscription(channelName);
|
||||||
|
messageBus.registerHandler(adapterName, adapter, subscription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,31 +19,30 @@ package org.springframework.integration.endpoint;
|
|||||||
import org.springframework.beans.factory.BeanNameAware;
|
import org.springframework.beans.factory.BeanNameAware;
|
||||||
import org.springframework.integration.MessageHandlingException;
|
import org.springframework.integration.MessageHandlingException;
|
||||||
import org.springframework.integration.MessagingConfigurationException;
|
import org.springframework.integration.MessagingConfigurationException;
|
||||||
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.channel.ChannelRegistry;
|
import org.springframework.integration.channel.ChannelRegistry;
|
||||||
|
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.handler.MessageHandler;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
import org.springframework.integration.scheduling.Schedule;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the {@link MessageEndpoint} interface.
|
* Default implementation of the {@link MessageEndpoint} interface.
|
||||||
*
|
*
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
public class DefaultMessageEndpoint implements MessageEndpoint, BeanNameAware {
|
public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryAware, BeanNameAware {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String inputChannelName;
|
|
||||||
|
|
||||||
private String defaultOutputChannelName;
|
|
||||||
|
|
||||||
private MessageHandler handler;
|
private MessageHandler handler;
|
||||||
|
|
||||||
private Schedule schedule;
|
private Subscription subscription;
|
||||||
|
|
||||||
private ConcurrencyPolicy concurrencyPolicy;
|
private ConcurrencyPolicy concurrencyPolicy;
|
||||||
|
|
||||||
|
private String defaultOutputChannelName;
|
||||||
|
|
||||||
private ChannelRegistry channelRegistry;
|
private ChannelRegistry channelRegistry;
|
||||||
|
|
||||||
|
|
||||||
@@ -59,18 +58,8 @@ public class DefaultMessageEndpoint implements MessageEndpoint, BeanNameAware {
|
|||||||
this.setName(beanName);
|
this.setName(beanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getDefaultOutputChannelName() {
|
||||||
* Set the name of the channel from which this endpoint receives messages.
|
return this.defaultOutputChannelName;
|
||||||
*/
|
|
||||||
public void setInputChannelName(String inputChannelName) {
|
|
||||||
this.inputChannelName = inputChannelName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the name of the channel from which this endpoint receives messages.
|
|
||||||
*/
|
|
||||||
public String getInputChannelName() {
|
|
||||||
return this.inputChannelName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,8 +69,8 @@ public class DefaultMessageEndpoint implements MessageEndpoint, BeanNameAware {
|
|||||||
this.defaultOutputChannelName = defaultOutputChannelName;
|
this.defaultOutputChannelName = defaultOutputChannelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultOutputChannelName() {
|
public MessageHandler getHandler() {
|
||||||
return this.defaultOutputChannelName;
|
return this.handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,12 +80,12 @@ public class DefaultMessageEndpoint implements MessageEndpoint, BeanNameAware {
|
|||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Schedule getSchedule() {
|
public Subscription getSubscription() {
|
||||||
return this.schedule;
|
return this.subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchedule(Schedule schedule) {
|
public void setSubscription(Subscription subscription) {
|
||||||
this.schedule = schedule;
|
this.subscription = subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrencyPolicy getConcurrencyPolicy() {
|
public ConcurrencyPolicy getConcurrencyPolicy() {
|
||||||
@@ -114,7 +103,7 @@ public class DefaultMessageEndpoint implements MessageEndpoint, BeanNameAware {
|
|||||||
this.channelRegistry = channelRegistry;
|
this.channelRegistry = channelRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
if (this.handler == null) {
|
if (this.handler == null) {
|
||||||
if (this.defaultOutputChannelName == null) {
|
if (this.defaultOutputChannelName == null) {
|
||||||
throw new MessagingConfigurationException(
|
throw new MessagingConfigurationException(
|
||||||
|
|||||||
@@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.integration.endpoint;
|
package org.springframework.integration.endpoint;
|
||||||
|
|
||||||
import org.springframework.integration.channel.ChannelRegistry;
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.handler.MessageHandler;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.scheduling.Schedule;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base interface for message endpoints.
|
* Base interface for message endpoints.
|
||||||
@@ -27,19 +26,11 @@ import org.springframework.integration.scheduling.Schedule;
|
|||||||
*/
|
*/
|
||||||
public interface MessageEndpoint extends MessageHandler {
|
public interface MessageEndpoint extends MessageHandler {
|
||||||
|
|
||||||
void setName(String name);
|
String getName();
|
||||||
|
|
||||||
void setInputChannelName(String inputChannelName);
|
MessageHandler getHandler();
|
||||||
|
|
||||||
String getInputChannelName();
|
Subscription getSubscription();
|
||||||
|
|
||||||
void setDefaultOutputChannelName(String defaultOutputChannelName);
|
|
||||||
|
|
||||||
String getDefaultOutputChannelName();
|
|
||||||
|
|
||||||
void setChannelRegistry(ChannelRegistry channelRegistry);
|
|
||||||
|
|
||||||
Schedule getSchedule();
|
|
||||||
|
|
||||||
ConcurrencyPolicy getConcurrencyPolicy();
|
ConcurrencyPolicy getConcurrencyPolicy();
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.message.GenericMessage;
|
import org.springframework.integration.message.GenericMessage;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
@@ -46,15 +47,16 @@ public class DefaultTargetAdapterTests {
|
|||||||
target.afterPropertiesSet();
|
target.afterPropertiesSet();
|
||||||
DefaultTargetAdapter adapter = new DefaultTargetAdapter(target);
|
DefaultTargetAdapter adapter = new DefaultTargetAdapter(target);
|
||||||
SimpleChannel channel = new SimpleChannel();
|
SimpleChannel channel = new SimpleChannel();
|
||||||
adapter.setChannel(channel);
|
Subscription subscription = new Subscription();
|
||||||
|
subscription.setChannel(channel);
|
||||||
Message<String> message = new GenericMessage<String>("123", "testing");
|
Message<String> message = new GenericMessage<String>("123", "testing");
|
||||||
channel.send(message);
|
channel.send(message);
|
||||||
assertNull(queue.poll());
|
assertNull(queue.poll());
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.registerChannel("channel", channel);
|
bus.registerChannel("channel", channel);
|
||||||
bus.registerTargetAdapter("targetAdapter", adapter);
|
bus.registerHandler("targetAdapter", adapter, subscription);
|
||||||
bus.start();
|
bus.start();
|
||||||
String result = queue.poll(100, TimeUnit.MILLISECONDS);
|
String result = queue.poll(500, TimeUnit.MILLISECONDS);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals("testing", result);
|
assertEquals("testing", result);
|
||||||
bus.stop();
|
bus.stop();
|
||||||
|
|||||||
@@ -29,13 +29,25 @@
|
|||||||
<property name="method" value="store"/>
|
<property name="method" value="store"/>
|
||||||
</bean>
|
</bean>
|
||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
<property name="channel" ref="outputChannel"/>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="targetEndpoint" class="org.springframework.integration.endpoint.DefaultMessageEndpoint">
|
||||||
|
<property name="handler" ref="targetAdapter"/>
|
||||||
|
<property name="subscription">
|
||||||
|
<bean class="org.springframework.integration.bus.Subscription">
|
||||||
|
<constructor-arg ref="outputChannel"/>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="sink" class="org.springframework.integration.adapter.TestSink"/>
|
<bean id="sink" class="org.springframework.integration.adapter.TestSink"/>
|
||||||
|
|
||||||
<bean id="endpoint" class="org.springframework.integration.endpoint.DefaultMessageEndpoint">
|
<bean class="org.springframework.integration.endpoint.DefaultMessageEndpoint">
|
||||||
<property name="inputChannelName" value="inputChannel"/>
|
<property name="subscription">
|
||||||
|
<bean class="org.springframework.integration.bus.Subscription">
|
||||||
|
<constructor-arg ref="inputChannel"/>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
<property name="defaultOutputChannelName" value="outputChannel"/>
|
<property name="defaultOutputChannelName" value="outputChannel"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.junit.Test;
|
|||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
|
import org.springframework.integration.bus.Subscription;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.message.StringMessage;
|
import org.springframework.integration.message.StringMessage;
|
||||||
@@ -46,10 +47,9 @@ public class ApplicationEventTargetAdapterTests {
|
|||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
ApplicationEventTargetAdapter adapter = new ApplicationEventTargetAdapter();
|
ApplicationEventTargetAdapter adapter = new ApplicationEventTargetAdapter();
|
||||||
adapter.setApplicationEventPublisher(publisher);
|
adapter.setApplicationEventPublisher(publisher);
|
||||||
adapter.setChannel(channel);
|
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.registerChannel("channel", channel);
|
bus.registerChannel("channel", channel);
|
||||||
bus.registerTargetAdapter("adapter", adapter);
|
bus.registerHandler("adapter", adapter, new Subscription(channel));
|
||||||
bus.start();
|
bus.start();
|
||||||
assertEquals(1, latch.getCount());
|
assertEquals(1, latch.getCount());
|
||||||
channel.send(new StringMessage("123", "testing"));
|
channel.send(new StringMessage("123", "testing"));
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||||
dispatcherTask.addHandler(adapter);
|
dispatcherTask.addHandler(adapter);
|
||||||
channel.send(new StringMessage("foo"));
|
channel.send(new StringMessage("foo"));
|
||||||
@@ -54,7 +53,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||||
dispatcherTask.addHandler(adapter);
|
dispatcherTask.addHandler(adapter);
|
||||||
channel.send(new StringMessage("foo"));
|
channel.send(new StringMessage("foo"));
|
||||||
@@ -72,7 +70,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
adapter.setShouldAppendNewLine(true);
|
adapter.setShouldAppendNewLine(true);
|
||||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||||
dispatcherTask.addHandler(adapter);
|
dispatcherTask.addHandler(adapter);
|
||||||
@@ -92,7 +89,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||||
retriever.setMaxMessagesPerTask(2);
|
retriever.setMaxMessagesPerTask(2);
|
||||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||||
@@ -109,7 +105,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
adapter.setShouldAppendNewLine(true);
|
adapter.setShouldAppendNewLine(true);
|
||||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||||
retriever.setReceiveTimeout(0);
|
retriever.setReceiveTimeout(0);
|
||||||
@@ -129,7 +124,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||||
dispatcherTask.addHandler(adapter);
|
dispatcherTask.addHandler(adapter);
|
||||||
TestObject testObject = new TestObject("foo");
|
TestObject testObject = new TestObject("foo");
|
||||||
@@ -145,7 +139,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||||
retriever.setReceiveTimeout(0);
|
retriever.setReceiveTimeout(0);
|
||||||
retriever.setMaxMessagesPerTask(2);
|
retriever.setMaxMessagesPerTask(2);
|
||||||
@@ -165,7 +158,6 @@ public class CharacterStreamTargetAdapterTests {
|
|||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
MessageChannel channel = new SimpleChannel();
|
MessageChannel channel = new SimpleChannel();
|
||||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||||
adapter.setChannel(channel);
|
|
||||||
adapter.setShouldAppendNewLine(true);
|
adapter.setShouldAppendNewLine(true);
|
||||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||||
retriever.setReceiveTimeout(0);
|
retriever.setReceiveTimeout(0);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.springframework.integration.MessageDeliveryException;
|
|||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.dispatcher.DefaultMessageDispatcher;
|
import org.springframework.integration.dispatcher.DefaultMessageDispatcher;
|
||||||
import org.springframework.integration.dispatcher.MessageHandlerRejectedExecutionException;
|
import org.springframework.integration.dispatcher.MessageHandlerRejectedExecutionException;
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.handler.PooledMessageHandler;
|
import org.springframework.integration.handler.PooledMessageHandler;
|
||||||
import org.springframework.integration.message.ErrorMessage;
|
import org.springframework.integration.message.ErrorMessage;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
@@ -467,19 +467,18 @@ public class DefaultMessageDispatcherTests {
|
|||||||
assertEquals("endpoint2 should have accepted the message", 1, counter2.get());
|
assertEquals("endpoint2 should have accepted the message", 1, counter2.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestEndpoint extends DefaultMessageEndpoint {
|
|
||||||
|
private static class TestEndpoint implements MessageHandler {
|
||||||
|
|
||||||
private AtomicInteger counter;
|
private AtomicInteger counter;
|
||||||
|
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
|
|
||||||
|
|
||||||
public TestEndpoint(AtomicInteger counter, CountDownLatch latch) {
|
public TestEndpoint(AtomicInteger counter, CountDownLatch latch) {
|
||||||
this.counter = counter;
|
this.counter = counter;
|
||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
import org.springframework.integration.message.GenericMessage;
|
import org.springframework.integration.message.GenericMessage;
|
||||||
import org.springframework.integration.scheduling.PollingSchedule;
|
import org.springframework.integration.scheduling.PollingSchedule;
|
||||||
@@ -44,8 +43,7 @@ public class FixedDelayConsumerTests {
|
|||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
||||||
SimpleChannel channel = new SimpleChannel();
|
SimpleChannel channel = new SimpleChannel();
|
||||||
MessageEndpoint endpoint = new DefaultMessageEndpoint() {
|
MessageHandler handler = new MessageHandler() {
|
||||||
@Override
|
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
@@ -55,7 +53,6 @@ public class FixedDelayConsumerTests {
|
|||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.initialize();
|
bus.initialize();
|
||||||
bus.registerChannel("testChannel", channel);
|
bus.registerChannel("testChannel", channel);
|
||||||
bus.registerEndpoint("testEndpoint", endpoint);
|
|
||||||
PollingSchedule schedule = new PollingSchedule(10);
|
PollingSchedule schedule = new PollingSchedule(10);
|
||||||
schedule.setFixedRate(false);
|
schedule.setFixedRate(false);
|
||||||
ConcurrencyPolicy concurrencyPolicy = new ConcurrencyPolicy();
|
ConcurrencyPolicy concurrencyPolicy = new ConcurrencyPolicy();
|
||||||
@@ -63,10 +60,8 @@ public class FixedDelayConsumerTests {
|
|||||||
concurrencyPolicy.setMaxConcurrency(1);
|
concurrencyPolicy.setMaxConcurrency(1);
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setSchedule(schedule);
|
subscription.setSchedule(schedule);
|
||||||
subscription.setConcurrencyPolicy(concurrencyPolicy);
|
subscription.setChannelName("testChannel");
|
||||||
subscription.setChannel("testChannel");
|
bus.registerHandler("testHandler", handler, subscription, concurrencyPolicy);
|
||||||
subscription.setHandler("testEndpoint");
|
|
||||||
bus.activateSubscription(subscription);
|
|
||||||
bus.start();
|
bus.start();
|
||||||
for (int i = 0; i < messagesToSend; i++) {
|
for (int i = 0; i < messagesToSend; i++) {
|
||||||
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
||||||
@@ -81,8 +76,7 @@ public class FixedDelayConsumerTests {
|
|||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
||||||
SimpleChannel channel = new SimpleChannel();
|
SimpleChannel channel = new SimpleChannel();
|
||||||
MessageEndpoint endpoint = new DefaultMessageEndpoint() {
|
MessageHandler handler = new MessageHandler() {
|
||||||
@Override
|
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
@@ -92,14 +86,12 @@ public class FixedDelayConsumerTests {
|
|||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.initialize();
|
bus.initialize();
|
||||||
bus.registerChannel("testChannel", channel);
|
bus.registerChannel("testChannel", channel);
|
||||||
bus.registerEndpoint("testEndpoint", endpoint);
|
|
||||||
PollingSchedule schedule = new PollingSchedule(10);
|
PollingSchedule schedule = new PollingSchedule(10);
|
||||||
schedule.setFixedRate(false);
|
schedule.setFixedRate(false);
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription(channel);
|
||||||
subscription.setChannel("testChannel");
|
subscription.setChannelName("testChannel");
|
||||||
subscription.setHandler("testEndpoint");
|
|
||||||
subscription.setSchedule(schedule);
|
subscription.setSchedule(schedule);
|
||||||
bus.activateSubscription(subscription);
|
bus.registerHandler("testHandler", handler, subscription);
|
||||||
for (int i = 0; i < messagesToSend; i++) {
|
for (int i = 0; i < messagesToSend; i++) {
|
||||||
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
import org.springframework.integration.message.GenericMessage;
|
import org.springframework.integration.message.GenericMessage;
|
||||||
import org.springframework.integration.scheduling.PollingSchedule;
|
import org.springframework.integration.scheduling.PollingSchedule;
|
||||||
@@ -44,8 +43,7 @@ public class FixedRateConsumerTests {
|
|||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
||||||
SimpleChannel channel = new SimpleChannel();
|
SimpleChannel channel = new SimpleChannel();
|
||||||
MessageEndpoint endpoint = new DefaultMessageEndpoint() {
|
MessageHandler handler = new MessageHandler() {
|
||||||
@Override
|
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
@@ -55,14 +53,12 @@ public class FixedRateConsumerTests {
|
|||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.initialize();
|
bus.initialize();
|
||||||
bus.registerChannel("testChannel", channel);
|
bus.registerChannel("testChannel", channel);
|
||||||
bus.registerEndpoint("testEndpoint", endpoint);
|
|
||||||
PollingSchedule schedule = new PollingSchedule(10);
|
PollingSchedule schedule = new PollingSchedule(10);
|
||||||
schedule.setFixedRate(true);
|
schedule.setFixedRate(true);
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setChannel("testChannel");
|
subscription.setChannelName("testChannel");
|
||||||
subscription.setHandler("testEndpoint");
|
|
||||||
subscription.setSchedule(schedule);
|
subscription.setSchedule(schedule);
|
||||||
bus.activateSubscription(subscription);
|
bus.registerHandler("testHandler", handler, subscription);
|
||||||
bus.start();
|
bus.start();
|
||||||
for (int i = 0; i < messagesToSend; i++) {
|
for (int i = 0; i < messagesToSend; i++) {
|
||||||
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
||||||
@@ -77,8 +73,7 @@ public class FixedRateConsumerTests {
|
|||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
final CountDownLatch latch = new CountDownLatch(messagesToSend);
|
||||||
SimpleChannel channel = new SimpleChannel();
|
SimpleChannel channel = new SimpleChannel();
|
||||||
MessageEndpoint endpoint = new DefaultMessageEndpoint() {
|
MessageHandler handler = new MessageHandler() {
|
||||||
@Override
|
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
@@ -86,20 +81,16 @@ public class FixedRateConsumerTests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.initialize();
|
|
||||||
bus.registerChannel("testChannel", channel);
|
|
||||||
bus.registerEndpoint("testEndpoint", endpoint);
|
|
||||||
PollingSchedule schedule = new PollingSchedule(5);
|
PollingSchedule schedule = new PollingSchedule(5);
|
||||||
schedule.setFixedRate(true);
|
schedule.setFixedRate(true);
|
||||||
ConcurrencyPolicy concurrencyPolicy = new ConcurrencyPolicy();
|
ConcurrencyPolicy concurrencyPolicy = new ConcurrencyPolicy();
|
||||||
concurrencyPolicy.setCoreConcurrency(1);
|
concurrencyPolicy.setCoreConcurrency(1);
|
||||||
concurrencyPolicy.setMaxConcurrency(1);
|
concurrencyPolicy.setMaxConcurrency(1);
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setChannel("testChannel");
|
subscription.setChannelName("testChannel");
|
||||||
subscription.setHandler("testEndpoint");
|
|
||||||
subscription.setSchedule(schedule);
|
subscription.setSchedule(schedule);
|
||||||
subscription.setConcurrencyPolicy(concurrencyPolicy);
|
bus.registerChannel("testChannel", channel);
|
||||||
bus.activateSubscription(subscription);
|
bus.registerHandler("testHandler", handler, subscription, concurrencyPolicy);
|
||||||
bus.start();
|
bus.start();
|
||||||
for (int i = 0; i < messagesToSend; i++) {
|
for (int i = 0; i < messagesToSend; i++) {
|
||||||
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
channel.send(new GenericMessage<String>(1, "test " + (i+1)));
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.springframework.integration.adapter.PollingSourceAdapter;
|
|||||||
import org.springframework.integration.adapter.SourceAdapter;
|
import org.springframework.integration.adapter.SourceAdapter;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
import org.springframework.integration.message.ErrorMessage;
|
import org.springframework.integration.message.ErrorMessage;
|
||||||
import org.springframework.integration.message.GenericMessage;
|
import org.springframework.integration.message.GenericMessage;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
@@ -45,25 +45,30 @@ import org.springframework.integration.message.StringMessage;
|
|||||||
public class MessageBusTests {
|
public class MessageBusTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChannelsConnectedWithEndpoint() {
|
public void testOutputChannel() {
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
MessageChannel sourceChannel = new SimpleChannel();
|
MessageChannel sourceChannel = new SimpleChannel();
|
||||||
MessageChannel targetChannel = new SimpleChannel();
|
MessageChannel targetChannel = new SimpleChannel();
|
||||||
bus.registerChannel("sourceChannel", sourceChannel);
|
bus.registerChannel("sourceChannel", sourceChannel);
|
||||||
sourceChannel.send(new StringMessage("123", "test"));
|
StringMessage message = new StringMessage("test");
|
||||||
|
message.getHeader().setReplyChannelName("targetChannel");
|
||||||
|
sourceChannel.send(message);
|
||||||
bus.registerChannel("targetChannel", targetChannel);
|
bus.registerChannel("targetChannel", targetChannel);
|
||||||
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
MessageHandler handler = new MessageHandler() {
|
||||||
endpoint.setInputChannelName("sourceChannel");
|
public Message<?> handle(Message<?> message) {
|
||||||
endpoint.setDefaultOutputChannelName("targetChannel");
|
return message;
|
||||||
bus.registerEndpoint("endpoint", endpoint);
|
}
|
||||||
|
};
|
||||||
|
Subscription subscription = new Subscription(sourceChannel);
|
||||||
|
bus.registerHandler("handler", handler, subscription);
|
||||||
bus.start();
|
bus.start();
|
||||||
Message<?> result = targetChannel.receive(100);
|
Message<?> result = targetChannel.receive(3000);
|
||||||
assertEquals("test", result.getPayload());
|
assertEquals("test", result.getPayload());
|
||||||
bus.stop();
|
bus.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChannelsWithoutEndpoint() {
|
public void testChannelsWithoutHandlers() {
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
MessageChannel sourceChannel = new SimpleChannel();
|
MessageChannel sourceChannel = new SimpleChannel();
|
||||||
sourceChannel.send(new StringMessage("123", "test"));
|
sourceChannel.send(new StringMessage("123", "test"));
|
||||||
@@ -84,31 +89,34 @@ public class MessageBusTests {
|
|||||||
sourceChannel.send(new GenericMessage<String>("123", "test"));
|
sourceChannel.send(new GenericMessage<String>("123", "test"));
|
||||||
MessageChannel targetChannel = (MessageChannel) context.getBean("targetChannel");
|
MessageChannel targetChannel = (MessageChannel) context.getBean("targetChannel");
|
||||||
MessageBus bus = (MessageBus) context.getBean("bus");
|
MessageBus bus = (MessageBus) context.getBean("bus");
|
||||||
Subscription subscription = new Subscription();
|
bus.start();
|
||||||
subscription.setChannel("sourceChannel");
|
Message<?> result = targetChannel.receive(1000);
|
||||||
subscription.setHandler("endpoint");
|
|
||||||
bus.activateSubscription(subscription);
|
|
||||||
Message<?> result = targetChannel.receive(100);
|
|
||||||
assertEquals("test", result.getPayload());
|
assertEquals("test", result.getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExactlyOneEndpointReceivesUnicastMessage() {
|
public void testExactlyOneHandlerReceivesPointToPointMessage() {
|
||||||
SimpleChannel inputChannel = new SimpleChannel();
|
SimpleChannel inputChannel = new SimpleChannel();
|
||||||
SimpleChannel outputChannel1 = new SimpleChannel();
|
SimpleChannel outputChannel1 = new SimpleChannel();
|
||||||
SimpleChannel outputChannel2 = new SimpleChannel();
|
SimpleChannel outputChannel2 = new SimpleChannel();
|
||||||
DefaultMessageEndpoint endpoint1 = new DefaultMessageEndpoint();
|
MessageHandler handler1 = new MessageHandler() {
|
||||||
endpoint1.setDefaultOutputChannelName("output1");
|
public Message<?> handle(Message<?> message) {
|
||||||
endpoint1.setInputChannelName("input");
|
message.getHeader().setReplyChannelName("output1");
|
||||||
DefaultMessageEndpoint endpoint2 = new DefaultMessageEndpoint();
|
return message;
|
||||||
endpoint2.setDefaultOutputChannelName("output2");
|
}
|
||||||
endpoint2.setInputChannelName("input");
|
};
|
||||||
|
MessageHandler handler2 = new MessageHandler() {
|
||||||
|
public Message<?> handle(Message<?> message) {
|
||||||
|
message.getHeader().setReplyChannelName("output2");
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
};
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
bus.registerChannel("input", inputChannel);
|
bus.registerChannel("input", inputChannel);
|
||||||
bus.registerChannel("output1", outputChannel1);
|
bus.registerChannel("output1", outputChannel1);
|
||||||
bus.registerChannel("output2", outputChannel2);
|
bus.registerChannel("output2", outputChannel2);
|
||||||
bus.registerEndpoint("endpoint1", endpoint1);
|
bus.registerHandler("handler1", handler1, new Subscription(inputChannel));
|
||||||
bus.registerEndpoint("endpoint2", endpoint2);
|
bus.registerHandler("handler2", handler2, new Subscription(inputChannel));
|
||||||
bus.start();
|
bus.start();
|
||||||
inputChannel.send(new StringMessage(1, "testing"));
|
inputChannel.send(new StringMessage(1, "testing"));
|
||||||
Message<?> message1 = outputChannel1.receive(100);
|
Message<?> message1 = outputChannel1.receive(100);
|
||||||
@@ -117,6 +125,39 @@ public class MessageBusTests {
|
|||||||
assertTrue("exactly one message should be null", message1 == null ^ message2 == null);
|
assertTrue("exactly one message should be null", message1 == null ^ message2 == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBothHandlersReceivePublishSubscribeMessage() {
|
||||||
|
SimpleChannel inputChannel = new SimpleChannel();
|
||||||
|
inputChannel.setBroadcaster(true);
|
||||||
|
SimpleChannel outputChannel1 = new SimpleChannel();
|
||||||
|
SimpleChannel outputChannel2 = new SimpleChannel();
|
||||||
|
MessageHandler handler1 = new MessageHandler() {
|
||||||
|
public Message<?> handle(Message<?> message) {
|
||||||
|
message.getHeader().setReplyChannelName("output1");
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MessageHandler handler2 = new MessageHandler() {
|
||||||
|
public Message<?> handle(Message<?> message) {
|
||||||
|
message.getHeader().setReplyChannelName("output2");
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MessageBus bus = new MessageBus();
|
||||||
|
bus.registerChannel("input", inputChannel);
|
||||||
|
bus.registerChannel("output1", outputChannel1);
|
||||||
|
bus.registerChannel("output2", outputChannel2);
|
||||||
|
bus.registerHandler("handler1", handler1, new Subscription(inputChannel));
|
||||||
|
bus.registerHandler("handler2", handler2, new Subscription(inputChannel));
|
||||||
|
bus.start();
|
||||||
|
inputChannel.send(new StringMessage(1, "testing"));
|
||||||
|
Message<?> message1 = outputChannel1.receive(100);
|
||||||
|
Message<?> message2 = outputChannel2.receive(0);
|
||||||
|
bus.stop();
|
||||||
|
assertTrue("both handlers should have received and replied to the message",
|
||||||
|
(message1 != null && message2 != null));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidMessageChannelWithFailedDispatch() throws InterruptedException {
|
public void testInvalidMessageChannelWithFailedDispatch() throws InterruptedException {
|
||||||
MessageBus bus = new MessageBus();
|
MessageBus bus = new MessageBus();
|
||||||
|
|||||||
@@ -11,7 +11,11 @@
|
|||||||
<bean id="targetChannel" class="org.springframework.integration.channel.SimpleChannel"/>
|
<bean id="targetChannel" class="org.springframework.integration.channel.SimpleChannel"/>
|
||||||
|
|
||||||
<bean id="endpoint" class="org.springframework.integration.endpoint.DefaultMessageEndpoint">
|
<bean id="endpoint" class="org.springframework.integration.endpoint.DefaultMessageEndpoint">
|
||||||
<property name="inputChannelName" value="sourceChannel"/>
|
<property name="subscription">
|
||||||
|
<bean class="org.springframework.integration.bus.Subscription">
|
||||||
|
<constructor-arg ref="sourceChannel"/>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
<property name="defaultOutputChannelName" value="targetChannel"/>
|
<property name="defaultOutputChannelName" value="targetChannel"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.channel.ChannelRegistry;
|
||||||
|
import org.springframework.integration.channel.DefaultChannelRegistry;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.channel.SimpleChannel;
|
import org.springframework.integration.channel.SimpleChannel;
|
||||||
import org.springframework.integration.handler.MessageHandler;
|
import org.springframework.integration.handler.MessageHandler;
|
||||||
@@ -35,49 +36,40 @@ public class DefaultMessageEndpointTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultReplyChannel() throws Exception {
|
public void testDefaultReplyChannel() throws Exception {
|
||||||
MessageChannel channel = new SimpleChannel();
|
|
||||||
MessageChannel replyChannel = new SimpleChannel();
|
MessageChannel replyChannel = new SimpleChannel();
|
||||||
|
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
|
||||||
|
channelRegistry.registerChannel("replyChannel", replyChannel);
|
||||||
MessageHandler handler = new MessageHandler() {
|
MessageHandler handler = new MessageHandler() {
|
||||||
public Message<String> handle(Message<?> message) {
|
public Message<String> handle(Message<?> message) {
|
||||||
return new StringMessage("123", "hello " + message.getPayload());
|
return new StringMessage("123", "hello " + message.getPayload());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
||||||
endpoint.setInputChannelName("testChannel");
|
endpoint.setChannelRegistry(channelRegistry);
|
||||||
endpoint.setHandler(handler);
|
endpoint.setHandler(handler);
|
||||||
endpoint.setDefaultOutputChannelName("replyChannel");
|
endpoint.setDefaultOutputChannelName("replyChannel");
|
||||||
MessageBus bus = new MessageBus();
|
endpoint.handle(new StringMessage(1, "test"));
|
||||||
bus.registerChannel("testChannel", channel);
|
Message<?> reply = replyChannel.receive(50);
|
||||||
bus.registerEndpoint("testEndpoint", endpoint);
|
|
||||||
bus.registerChannel("replyChannel", replyChannel);
|
|
||||||
bus.start();
|
|
||||||
StringMessage testMessage = new StringMessage(1, "test");
|
|
||||||
channel.send(testMessage);
|
|
||||||
Message<String> reply = replyChannel.receive(50);
|
|
||||||
assertNotNull(reply);
|
assertNotNull(reply);
|
||||||
assertEquals("hello test", reply.getPayload());
|
assertEquals("hello test", reply.getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitReplyChannel() throws Exception {
|
public void testExplicitReplyChannel() throws Exception {
|
||||||
MessageChannel channel = new SimpleChannel();
|
|
||||||
final MessageChannel replyChannel = new SimpleChannel();
|
final MessageChannel replyChannel = new SimpleChannel();
|
||||||
|
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
|
||||||
|
channelRegistry.registerChannel("replyChannel", replyChannel);
|
||||||
MessageHandler handler = new MessageHandler() {
|
MessageHandler handler = new MessageHandler() {
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
return new StringMessage("123", "hello " + message.getPayload());
|
return new StringMessage("123", "hello " + message.getPayload());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint();
|
||||||
endpoint.setInputChannelName("testChannel");
|
endpoint.setChannelRegistry(channelRegistry);
|
||||||
endpoint.setHandler(handler);
|
endpoint.setHandler(handler);
|
||||||
MessageBus bus = new MessageBus();
|
|
||||||
bus.registerChannel("testChannel", channel);
|
|
||||||
bus.registerEndpoint("testEndpoint", endpoint);
|
|
||||||
bus.registerChannel("replyChannel", replyChannel);
|
|
||||||
bus.start();
|
|
||||||
StringMessage testMessage = new StringMessage(1, "test");
|
StringMessage testMessage = new StringMessage(1, "test");
|
||||||
testMessage.getHeader().setReplyChannelName("replyChannel");
|
testMessage.getHeader().setReplyChannelName("replyChannel");
|
||||||
channel.send(testMessage);
|
endpoint.handle(testMessage);
|
||||||
Message<?> reply = replyChannel.receive(50);
|
Message<?> reply = replyChannel.receive(50);
|
||||||
assertNotNull(reply);
|
assertNotNull(reply);
|
||||||
assertEquals("hello test", reply.getPayload());
|
assertEquals("hello test", reply.getPayload());
|
||||||
|
|||||||
Reference in New Issue
Block a user