Announcement Announcement Module
Collapse
No announcement yet.
Accessing Dynamic Router Capabilities from XML Configured Routers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing Dynamic Router Capabilities from XML Configured Routers

    Hey guys,

    I'm looking for a way to access the dynamic router capabilities of the built-in routers programmatically. I know that classes such as HeaderValueRouter expose setChannelMapping() and removeChannelMapping(), but I have not been able to find a clean way to obtain a reference to an instance of this class from a header-value-router bean.

    I know that I can extend EventDrivenConsumer and initialize it with my own instance of a HeaderValueRouter (or derived type), but this feels a little too tightly bound to framework.

    My use case is that I want to configure a router statically, but then modify it at run time.

  • #2
    These methods are exposed as operations over JMX, and available via the <control-bus/>...

    Code:
    <int:control-bus input-channel="control"/>
    	
    <int:router id="hvr2" input-channel="x" ref="controlledHVR"/>
    
    <bean id="controlledHVR" class="org.springframework.integration.router.HeaderValueRouter">
    	<constructor-arg value="routing.header" />
    	<property name="channelMappings" ref="initialMap" />
    </bean>
    	
    <util:map id="initialMap">
    	<entry key="foo" value="bar"/>
    </util:map>
    Just send a message containing "@controlledHVR.setChannelMapping('baz', 'qux')" to the control channel.

    Or, you can use raw JMX...

    Code:
    <context:mbean-server />
    
    <int-jmx:mbean-export default-domain="test.domain" />
    
    <int:header-value-router id="hvr" input-channel="x" header-name="routing.header">
    	<int:mapping value="foo" channel="y"/>
    </int:header-value-router>
    Code:
    List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
    // verify you only have one, or figure out which one you want
    MBeanServer server = servers.get(0);
    server.invoke(new ObjectName(
    		"test.domain:type=HeaderValueRouter,name=hvr"),
    		"setChannelMapping", new Object[] { "baz", "quz" },
    		new String[] { "java.lang.String", "java.lang.String" });
    Note that you can't use the <control-bus/> at the same time as the MBean exporter - this might be a bug; I need to think about it some more.

    Also, we have an open JIRA to expose a single call to replace the entire channel mappings in an atomic update over JMX...

    https://jira.springsource.org/browse/INT-2352

    Of course, with the first configuration above, you can inject the HVR into your own class and invoke its methods directly.

    Comment


    • #3
      Thanks, that helps!

      Our basic problem can probably be solved by just manually creating a bean for the HeaderValueRouter, but tying in the <control-bus /> or using JMX may actually be better for our overall design. So far JMX integration isn't something my team has not explored much. As with the control bus, we'll have to play with it a little more to see exactly what we can do with it -particularly since both methods seem to simplify many of our run-time reconfiguration concerns.

      Thanks again!

      Comment

      Working...
      X