Announcement Announcement Module
No announcement yet.
Suggestion required Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Suggestion required

    At times, we are using non-annotated java routers, which internally determine the output channel to which the message should be sent.

    Those channel names have to hard coded within the java class itself.

    Problem arises, when some other person changes the channel Id in the config file, and forgets to change that in the router class (a very common and genuine mistake in my view).

    I am trying to find out a solution to this, but cannot think anything top of my head.

    Any suggestions?

  • #2
    You could add something like...

    	ApplicationContext context;
    	public void init() {
    		String[] channels = context.getBeanNamesForType(MessageChannel.class);
    ...and validate that all the channel names in your java class exist in the context. If you want to force the application context to fail to load if someone has made such a change, do the validation and throw an exception in an @PostConstruct method (or implement IniaitlizingBean and do the check in afterPropertiesSet()).
    Last edited by Gary Russell; Nov 18th, 2010, 01:21 PM.


    • #3
      Have you tried using Expression language to give the channel name? you can have a enum or some bean with constants and refer that both in the integration file and java classes so it is consistent.
      I haven't tried thinking it should work though


      • #4
        You should be able to use @Autowired on a Map<String, MessageChannel> property actually, and then you don't need to do the lookup.

        However, it sounds like you might want to look into the use of <router> with a <mapping> sub-element. That basically gives you a level of indirection so that you can always return "foo" but then have it map to "bar" like so:
        <router input-channel="in" ref="someBean" method="someMethod">
           <mapping value="foo" channel="bar"/>


        • #5
          Thanks for the valued feedbacks.

          I think using a mapping element within router declaration will serve my purpose.


          • #6
            Well, it seems this feature was added in 2.0 so I couldn't get this option in my IDE.
            I am still on 1.0.3, and unfortunately, cannot use the value / channel mapping.


            • #7
              I've tried srinivas_vsk's option before. That works quite well. The mapping subelement is a little less work, but it means you'd still have to change a string in two places.