Add localName property to channel specs (read only)
/channels/taps responds to the local name as well as the "channel" name. Also includes a change to allow the default channel name to be output_topic: or input_topic: (for pubsub but no particular name). And also adds autoStartup to module properties.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.bus.runner.adapter;
|
||||
|
||||
import org.springframework.integration.support.context.NamedComponent;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -38,6 +39,11 @@ public class InputChannelSpec {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return (channel instanceof NamedComponent) ? ((NamedComponent) channel)
|
||||
.getComponentName() : channel.toString();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public MessageChannel getMessageChannel() {
|
||||
return channel;
|
||||
|
||||
@@ -129,6 +129,11 @@ public class MessageBusAdapter implements Lifecycle, ApplicationContextAware {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
for (OutputChannelSpec spec : outputChannels) {
|
||||
if (name.equals(spec.getLocalName())) {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -141,6 +146,11 @@ public class MessageBusAdapter implements Lifecycle, ApplicationContextAware {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
for (InputChannelSpec spec : inputChannels) {
|
||||
if (name.equals(spec.getLocalName())) {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +28,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class LifecycleConfiguration implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private MessageBusProperties module;
|
||||
|
||||
@Autowired
|
||||
private MessageBusAdapter adapter;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
if (!adapter.isRunning()) {
|
||||
if (!adapter.isRunning() && module.isAutoStartup()) {
|
||||
adapter.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.xd.dirt.integration.bus.MessageBus;
|
||||
import org.springframework.xd.dirt.integration.bus.MessageBusAwareRouterBeanPostProcessor;
|
||||
|
||||
import reactor.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -68,11 +70,12 @@ public class MessageBusAdapterConfiguration {
|
||||
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory,
|
||||
MessageChannel.class);
|
||||
for (String name : names) {
|
||||
String channelName = extractChannelName("output", name, module.getOutputChannelName());
|
||||
String channelName = extractChannelName("output", name,
|
||||
module.getOutputChannelName());
|
||||
if (channelName != null) {
|
||||
OutputChannelSpec channel = new OutputChannelSpec(channelName,
|
||||
beanFactory.getBean(name, MessageChannel.class));
|
||||
String tapChannelName = !channelName.equals(module.getOutputChannelName()) ? module
|
||||
String tapChannelName = !isDefaultOuputChannel(channelName) ? module
|
||||
.getTapChannelName(getPlainChannelName(channel.getName()))
|
||||
: module.getTapChannelName();
|
||||
channel.setTapChannelName(tapChannelName);
|
||||
@@ -83,7 +86,16 @@ public class MessageBusAdapterConfiguration {
|
||||
return channels;
|
||||
}
|
||||
|
||||
private String extractChannelName(String start, String name, String externalChannelName) {
|
||||
private boolean isDefaultOuputChannel(String channelName) {
|
||||
if (channelName.contains(":")) {
|
||||
String[] tokens = channelName.split(":", 2);
|
||||
channelName = tokens[1];
|
||||
}
|
||||
return channelName.equals(module.getOutputChannelName());
|
||||
}
|
||||
|
||||
private String extractChannelName(String start, String name,
|
||||
String externalChannelName) {
|
||||
if (name.equals(start)) {
|
||||
return externalChannelName;
|
||||
}
|
||||
@@ -95,10 +107,12 @@ public class MessageBusAdapterConfiguration {
|
||||
String type = tokens[0];
|
||||
if ("queue".equals(type)) {
|
||||
// omit the type for a queue
|
||||
prefix = tokens[1] + ".";
|
||||
if (StringUtils.hasText(tokens[1])) {
|
||||
prefix = tokens[1] + ".";
|
||||
}
|
||||
}
|
||||
else {
|
||||
prefix = channelName + ".";
|
||||
prefix = channelName + (channelName.endsWith(":") ? "" : ".");
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -121,7 +135,8 @@ public class MessageBusAdapterConfiguration {
|
||||
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory,
|
||||
MessageChannel.class);
|
||||
for (String name : names) {
|
||||
String channelName = extractChannelName("input", name, module.getInputChannelName());
|
||||
String channelName = extractChannelName("input", name,
|
||||
module.getInputChannelName());
|
||||
if (channelName != null) {
|
||||
channels.add(new InputChannelSpec(channelName, beanFactory.getBean(name,
|
||||
MessageChannel.class)));
|
||||
|
||||
@@ -51,6 +51,8 @@ public class MessageBusProperties {
|
||||
|
||||
private Tap tap;
|
||||
|
||||
private boolean autoStartup = true;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -130,6 +132,14 @@ public class MessageBusProperties {
|
||||
this.producerProperties = producerProperties;
|
||||
}
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
return autoStartup;
|
||||
}
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
public Tap getTap() {
|
||||
return tap;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,15 @@ public class MessageBusAdapterConfigurationTests {
|
||||
assertEquals("tap:stream:group.module.0", channels.iterator().next().getTapChannelName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneOutputTopic() throws Exception {
|
||||
context.registerSingleton("output.topic:", new DirectChannel());
|
||||
Collection<OutputChannelSpec> channels = configuration.getOutputChannels();
|
||||
assertEquals(1, channels.size());
|
||||
assertEquals("topic:group.0", channels.iterator().next().getName());
|
||||
assertEquals("tap:stream:group.module.0", channels.iterator().next().getTapChannelName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoOutputsWithTopic() throws Exception {
|
||||
context.registerSingleton("output", new DirectChannel());
|
||||
|
||||
Reference in New Issue
Block a user