Announcement Announcement Module
Collapse
No announcement yet.
control bus integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • control bus integration

    i really like this addition ;
    i defined a control bus along with a gateway to link it with the command :

    Code:
    <context:annotation-config/>
    
    	<int:channel id="request-command"/>
    	<int:channel id="respons-command"/>
    
    	<int:gateway default-request-channel="request-command" default-reply-channel="respons-command" service-interface="wims.tijd.shell.ControlBusGateway" />
    
    	<int:control-bus input-channel="request-command" output-channel="respons-command"/>
    	
    	<bean class="wims.tijd.shell.ControlBusCommand"/>
    Code:
    public interface ControlBusGateway {
    	
    	@Gateway
    	Object send(String command);
    
    }
    Code:
    @Component
    public class ControlBusCommand implements CommandMarker, ApplicationContextAware {
    	
    	@Inject ControlBusGateway cbg;
    	
    	ApplicationContext applicationContext;
    	
    	@CliCommand(value = "controlbus", help = "Print a simple hello world message")
    	public String send(
    			@CliOption(key = { "identifier" }, mandatory = true, help = "Beanname") final String identifier,
    			@CliOption(key = { "operation" }, mandatory = true, help = "Method") final String operation){
    		
    		Object returned = cbg.send("@'"+identifier+"'."+operation);
    		if(returned == null){
    			return "command exucted.";
    		}else{
    			return returned.toString();
    		}
    	}
    	
    	@CliCommand(value = "listBeans", help = "Print a simple hello world message")
    	public String listBeans(){
    		
    		StringBuilder sb = new StringBuilder(this.applicationContext.getDisplayName()).append("\n");
    		
    		
    		for(String name : this.applicationContext.getBeanDefinitionNames()){
    			sb.append(name).append("=").append(this.applicationContext.getBean(name).getClass()).append("\n");
    		}
    		
    		return sb.toString();
    		
    	}
    
    	@Override
    	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    		this.applicationContext = applicationContext;
    	}
    
    }
    Code:
    spring-shell>controlbus --identifier errorChannel --operation componentType
    publish-subscribe-channel
    spring-shell>

  • #2
    Hi,

    Nice to hear you are finding it useful. One improvement I can suggest for this command is to pass in the SpEL expression vs. separating it out into the bean name and the operations that assumes no-arg. Quite a few SI operations like channel adapter start, stop, status take zero arguments, but in more complex cases there will be method arguments. Also, the control bus can also take groovy or other JVM based scripts... what about

    >controlbus --spel -expression @bean.operation("foo","bar",1)
    >controlbus --script cool-script.groovy


    Cheers,
    Mark

    Comment


    • #3
      Nice post.. Thanks for sharing such a best information. It is more useful.

      Comment

      Working...
      X