Add /channels/taps MVC endpoint
This commit is contained in:
@@ -116,6 +116,57 @@ public class MessageBusAdapter implements Lifecycle, ApplicationContextAware {
|
||||
this.inputChannels = new LinkedHashSet<InputChannelSpec>(inputChannels);
|
||||
}
|
||||
|
||||
public Collection<OutputChannelSpec> getOutputChannels() {
|
||||
return outputChannels;
|
||||
}
|
||||
|
||||
public OutputChannelSpec getOutputChannel(String name) {
|
||||
if (name==null) {
|
||||
return null;
|
||||
}
|
||||
for (OutputChannelSpec spec : outputChannels) {
|
||||
if (name.equals(spec.getName())) {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public InputChannelSpec getInputChannel(String name) {
|
||||
if (name==null) {
|
||||
return null;
|
||||
}
|
||||
for (InputChannelSpec spec : inputChannels) {
|
||||
if (name.equals(spec.getName())) {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<InputChannelSpec> getInputChannels() {
|
||||
return inputChannels;
|
||||
}
|
||||
|
||||
public void tap(String outputChannel) {
|
||||
OutputChannelSpec channel = getOutputChannel(outputChannel);
|
||||
if (channel==null || channel.isTapped()) {
|
||||
return;
|
||||
}
|
||||
createAndBindTapChannel(channel.getTapChannelName(), channel.getMessageChannel());
|
||||
channel.setTapped(true);
|
||||
}
|
||||
|
||||
public void untap(String outputChannel) {
|
||||
OutputChannelSpec channel = getOutputChannel(outputChannel);
|
||||
if (channel==null || !channel.isTapped()) {
|
||||
return;
|
||||
}
|
||||
String tapChannelName = channel.getTapChannelName();
|
||||
messageBus.unbindProducers(tapChannelName);
|
||||
channel.setTapped(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ManagedOperation
|
||||
public void start() {
|
||||
@@ -289,4 +340,5 @@ public class MessageBusAdapter implements Lifecycle, ApplicationContextAware {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
*/
|
||||
public class OutputChannelSpec extends InputChannelSpec {
|
||||
|
||||
private boolean tapped;
|
||||
private boolean tapped = false;
|
||||
private String tapChannelName;
|
||||
|
||||
public OutputChannelSpec(String name, MessageChannel channel) {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2015 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.bus.runner.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.bus.runner.adapter.MessageBusAdapter;
|
||||
import org.springframework.bus.runner.adapter.OutputChannelSpec;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class ChannelsEndpoint extends AbstractEndpoint<Map<String, ?>> {
|
||||
|
||||
private MessageBusProperties module;
|
||||
private MessageBusAdapter adapter;
|
||||
|
||||
public ChannelsEndpoint(MessageBusProperties module, MessageBusAdapter adapter) {
|
||||
super("channels");
|
||||
this.module = module;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/channels/taps")
|
||||
public List<OutputChannelSpec> taps() {
|
||||
List<OutputChannelSpec> list = new ArrayList<OutputChannelSpec>();
|
||||
for (OutputChannelSpec spec : adapter.getOutputChannels()) {
|
||||
if (spec.isTapped()) {
|
||||
list.add(spec);
|
||||
}
|
||||
}
|
||||
return list ;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/channels/taps", method=RequestMethod.POST)
|
||||
public OutputChannelSpec tap(@RequestParam String channel) {
|
||||
adapter.tap(channel);
|
||||
return adapter.getOutputChannel(channel);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/channels/taps", method=RequestMethod.DELETE)
|
||||
public OutputChannelSpec untap(@RequestParam String channel) {
|
||||
adapter.untap(channel);
|
||||
return adapter.getOutputChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ?> invoke() {
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
map.put("inputChannels", adapter.getInputChannels());
|
||||
map.put("outputChannels", adapter.getOutputChannels());
|
||||
map.put("module", module);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,16 +16,13 @@
|
||||
package org.springframework.bus.runner.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.bus.runner.adapter.InputChannelSpec;
|
||||
import org.springframework.bus.runner.adapter.MessageBusAdapter;
|
||||
@@ -63,17 +60,8 @@ public class MessageBusAdapterConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AbstractEndpoint<?> messageBusEndpoint() {
|
||||
return new AbstractEndpoint<Map<String, ?>>("messages") {
|
||||
@Override
|
||||
public Map<String, ?> invoke() {
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
map.put("inputChannels", getInputChannels());
|
||||
map.put("outputChannels", getOutputChannels());
|
||||
map.put("module", module);
|
||||
return map;
|
||||
}
|
||||
};
|
||||
public ChannelsEndpoint channelsEndpoint(MessageBusAdapter adapter) {
|
||||
return new ChannelsEndpoint(module, adapter);
|
||||
}
|
||||
|
||||
protected Collection<OutputChannelSpec> getOutputChannels() {
|
||||
@@ -110,7 +98,7 @@ public class MessageBusAdapterConfiguration {
|
||||
.getTapChannelName(getPlainChannelName(channel.getName()))
|
||||
: module.getTapChannelName();
|
||||
channel.setTapChannelName(tapChannelName);
|
||||
channel.setTapped(true); // TODO: determine when this is the case
|
||||
channel.setTapped(false);
|
||||
channels.add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.bus.runner.adapter.InputChannelSpec;
|
||||
import org.springframework.bus.runner.adapter.OutputChannelSpec;
|
||||
import org.springframework.bus.runner.config.MessageBusAdapterConfigurationTests.Empty;
|
||||
import org.springframework.bus.runner.config.MessageBusProperties.Tap;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
Reference in New Issue
Block a user