Announcement Announcement Module
Collapse
No announcement yet.
Missing configuration or possible bug about int:router + List<MessageChannel> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Missing configuration or possible bug about int:router + List<MessageChannel>

    Hello guys

    I am working and testing the section Configuring a Router with Annotations where appear the follow snippet code


    @Router
    public MessageChannel route(Message message) {...}

    @Router
    public List<MessageChannel> route(Message message) {...}


    @Router
    public String route(Foo payload) {...}

    @Router
    public List<String> route(Foo payload) {...}
    I tested each approach about the return type but the second does not work

    For example if I work with List<String>

    Code:
    <int:router id="router" 
    		input-channel="inicio"
      	        apply-sequence="true"
    		method="metodoRouter01"							
    		ref="myRouterSinAnnotationTres"	
    />
    
    private List<String> listChannels;
    	
    public MyRouterConAnnotationTres(){
    	listChannels = new ArrayList<String>();
    	listChannels.add("dvdChannel");
    	listChannels.add("instrumentoMusicalChannel");		
    }
    	
    @Router
    public List<String> metodoRouter01(Message<?> message){
    			
    	logger.info("... message: {}", message);
    		
    	return listChannels;		
    }
    It work fine

    But If I work with List<MessageChannel>

    Code:
    <int:router id="router" 
    		input-channel="inicio"
    		apply-sequence="true"
    		method="metodoRouter01"
    		ref="myRouterSinAnnotationCuatro"	
    				/>
    
    private List<MessageChannel> listChannels;
    	
    private DirectChannel dvdChannel;	
    private DirectChannel instrumentoMusicalChannel;
    	
    @Value("#{dvdChannel}")
    public void setDvdChannel(DirectChannel dvdChannel) {
    	this.dvdChannel = dvdChannel;
    }	
    	
    @Value("#{instrumentoMusicalChannel}")
    public void setInstrumentoMusicalChannel(DirectChannel instrumentoMusicalChannel) {
    	this.instrumentoMusicalChannel = instrumentoMusicalChannel;
    }
    	
    public MyRouterSinAnnotationCuatro(){
    	listChannels = new ArrayList<MessageChannel>();
    	listChannels.add(dvdChannel);
    	listChannels.add(instrumentoMusicalChannel);
    }
    		
    public List<MessageChannel> metodoRouter01(Message<?> message){
    				
    	logger.info("... message: {}", message);
    	return listChannels;		
    }
    does not work I dont receive none exception

    How I know it does not work?, simply I have two flow integration files

    one working with List<String> and the second with List<MessageChannel>, each file has

    Code:
    <int:message-history/>
    
    <int:wire-tap pattern="*" channel="logger" />
    	
    <int:logging-channel-adapter id="logger"								 
    				 level="INFO"								 					 
    				 log-full-message="true"	
    				/>
    For the case with List<String> I can see through the history for each Message sent, the follow history:

    startChannel, router->outputchannel, some ServiceActivator, finalChannel


    But with List<MessageChannel> I can see only the follow history for each Message sent it, everyone has the follow sequence:

    startChannel, router->XXX


    I mean with XXX that each Message<T> never left the router, what is wrong?

    I have the same weird behaviour even If I work with List<DirectChannel>

    Thanks in advanced

  • #2
    The reason List<MessageChannel> is not working is because you are initializing the channel list in the constructor. This happens before Spring invokes the setters so listChannels = [null,null]. You need to do something like:
    Code:
    @PostConstruct
    	public void init() {
    		listChannels = new ArrayList<MessageChannel>();
    		listChannels.add(dvdChannel);
    		listChannels.add(instrumentoMusicalChannel);
    	}
    List<String> works because you are setting string literals.

    Comment


    • #3
      Hello dturanski

      Thanks so much for the explanation

      Wooh this kind of error is unforgivable

      The reason List<MessageChannel> is not working is because you are initializing the channel list in the constructor. This happens before Spring invokes the setters so listChannels = [null,null].
      Yes I did realize with

      Code:
      for(MessageChannel messageChannel : listChannels){
      			
      	if(messageChannel==null)
      		logger.error("++++++++++SI SOY NULL++++++++");
      	else
      		logger.info("-----------------NO SOY NULL-------------");
      	}
      and I forgot include resolution-required="true" to see the problem

      List<String> works because you are setting string literals.
      Yes, there is no need to wait some initialization or injection of dependencies by the container

      I forgot by complete the order of work
      1. creation target object (by its constructor)
      2. setter injection and/or constructor injection

      Thanks for your time

      Best Regards
      Last edited by dr_pompeii; Aug 24th, 2011, 11:03 AM.

      Comment

      Working...
      X