Announcement Announcement Module
Collapse
No announcement yet.
Custom Router,Please help... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Router,Please help...

    I need to build the Router logic for my msg pipe. Diff chanell will use diff XSD to Transform XML data to txt format.if you have any examples,please let me know.
    Thank you

  • #2
    which is it that you are looking for Routing or Transformation?

    Comment


    • #3
      I'm looking for a custom router logic.My msg's are in XML format.

      I need to build the router logic to output message to different channel.Each channel will use XSD file for XML parser(jaxb),so I can get access to msg data in transformer.

      For example: if Mesage Name is "ABC" --->channel is "XYZ" and XSD file for this chanell to pars xml will be "YYY" .


      Thank you vm for your help....

      Comment


      • #4
        What do you mean channels with XSD? Channels only receive and dispatch (not process) messages? Look at them as connectors between endpoints.
        As for the routers there ar numerous routing techniques currently available within Spring Integration which means there is more then one way to do the same operation (routing in your case), so when you say "Massage Name ABC" - what is ABC? payload? header name/value? something inside the payload?

        Please be more descriptive as to what are you trying to accomplish

        Comment


        • #5
          Very sorry if I'm not clear,plus I'm new to Integration:

          I'm doing the fillowing steps in my process.

          1.I'm spolling the directory to get incoming msg as XML file.
          2.I push msg to the channel
          3.I transform the xml msg to text(Swift) format msg.
          4.Log msg to DB table
          6.Send msg to MQ.

          Now for step #3 I use the XML schema file(.xsd) to parce the XML msg and get Mesage data value in Transformer.When it parce(jaxb) the new java class is created to get data value.
          Issue with XML schema:
          I can not parce the XML msg with the same schema.I have 3 different Message format. Based on msg type(payload) ,Message needs to be parce with different schema.
          I think I need to implement the Router to output msg to different channel for parcing and use different transformer for each channel.



          Thank you for help...
          Last edited by mikespring69; Jun 25th, 2010, 03:03 PM.

          Comment


          • #6
            Since you said you need to route it based on payload type all you need is PayloadTypeRouter which will route incoming message to different channels based on the payload type of the incoming message and could be easily configured as such:

            Code:
            <si:payload-type-router input-channel="some-channel">
            		<si:mapping type="java.lang.String" channel="chanel-for-strings"/>
            		<si:mapping type="org.foo.Bar" channel="chanel-for-bars"/>
            </si:payload-type-router>
            	
            <si:transformer input-channel="chanel-for-strings" ...>
            		. . . .
            </si:transformer>
            	
            <si:transformer input-channel="chanel-for-bars" ...>
            		. . . .
            </si:transformer>

            Comment


            • #7
              The Payload will represent my xml msg,can I get the field value inside of my PayloadRouter? -For example ,I have xml file with field:

              <MessageType>Transfer</MessageType>

              if MessageType="Transfer" then channel="abc"

              Comment


              • #8
                Yes you can. Look at XPath router samples here:
                https://src.springsource.org/svn/spr...on/xml/router/

                Comment


                • #9
                  Oleg, Thank you for help!!!

                  Comment


                  • #10
                    Please help, I stuck here, What should be the syntax to get channel value from my customRouterBean SwiftMainRouter.java


                    <beans:bean id="customRouterBean"

                    class="com.util.SwiftMainRouter">

                    ???????????

                    </beans:bean>



                    public class SwiftMainRouter extends AbstractMessageRouter {

                    ChannelResolver channelResolver;
                    MessageChannel channel =null;

                    @Override
                    protected Collection<MessageChannel> determineTargetChannels(
                    Message<?> message) {
                    // TODO Auto-generated method stub


                    System.out.println("Hello from Custom Router");

                    if (message == null)
                    {
                    throw new MessagingException("SwiftMainRouter.java-Expected message but is null");
                    }

                    String channelName="";

                    String msg = message.getPayload().toString();

                    Collection<MessageChannel> channels = new ArrayList<MessageChannel>();


                    if(!msg.equalsIgnoreCase("A"))
                    {
                    channelName = "inboundAdapter";
                    }

                    channel = channelResolver.resolveChannelName(channelName);

                    if (channel==null)
                    {
                    throw new MessagingException(message, "failed to resolve channel name '" + channelName + "'");
                    }

                    channels.add(channel);


                    return channels;
                    }

                    Comment


                    • #11
                      I am not sure I understand the question. What channel?
                      Router receives on input-channel and routs the messages to 'other channels' based on the type of router.
                      If you are writing a completely new router then you are responsible to provide routing logic and maintain collection of channels it will route to.
                      Once you create this bean you configure is as such:
                      Code:
                      <int:channel id="input"/>
                      
                      <int:router input-channel="input" ref="myRouter"/>
                      
                      <bean id="myRouter" class="foo.bar.MyRouter">
                      <!-- this is where you might want to inject a collection of channels you want to route -->
                      </bean>
                      Also, I thought you were routing based on XML. Have you look at XPath router support?

                      Comment


                      • #12
                        yes, This is what have now:


                        <router input-channel="transformInChannel" ref="customRouterBean"/>
                        <beans:bean id="customRouterBean"
                        class="util.SwiftMainRouter">

                        ????????


                        </beans:bean>

                        Please I need injection syntax,How to get channel value from SwiftMainRouter.java

                        Comment


                        • #13
                          What channel?

                          Comment


                          • #14
                            Can you please look to my SwiftMainRouter.java class it return the channel "other-channel",Can you please call me to discuss???? -if it's possible...

                            Comment


                            • #15
                              What I think you are asking is how to inject channels into your custom router.
                              You do it through basic Spring dependency injection, you can read more on it here: http://static.springsource.org/sprin...s-dependencies

                              In your particular case you probably want to inject some type of collection of channels, again here is documentation on how to inject collections: http://static.springsource.org/sprin...ction-elements

                              You still did not answer as to why you are not using XPath routers which probably provide all the functionality you need instead of implementing your own class.

                              Comment

                              Working...
                              X