5 Replies Latest reply on Oct 27, 2014 6:35 AM by Jorge Morales

    How to make Camel filter in SwitchYard component

    Tung Tran Newbie

      Hi everybody,

      There are some ways to filter a Bean component in Camel. One of the most simple way is using method name.

      <route>
      <from uri="direct:start"/>
      <filter>
      <method ref="myPredicate"method="isWhatIWant"/>
      <to uri="mock:boston"/>
      </filter>
      </route>
      

       

      So, Is there any way to make Filter works with SwitchYard component by method name?

        • 1. Re: How to make Camel filter in SwitchYard component
          Jorge Morales Master

          Hi Tung,

          This should work out of the box with SwitchYard. Make the Bean a @Named bean and use filter to select the method. I haven't tried it, but should work as it is Camel feature.

           

          from("switchyard://StartService")
          .filter().method(MyBean.class, "isWhatIWant").to("switchyard://BostonService").end();
          

           

          It is just a matter of you trying.

          • 2. Re: How to make Camel filter in SwitchYard component
            Tung Tran Newbie

            Hi Jorge. There is no Bean in here. My Component has the Java interface and Java Camel DSL as the component's implementation. The Java interface has methods and I want to divide the invocation of each method to separating processing, for example:

             

            from("switchyard://PersonManagement")

            // if invoked method was save

            to("sql:persistSomething....")

            // if invoked method was delete

            to("sql:deleteSomething...")

            • 3. Re: How to make Camel filter in SwitchYard component
              Jorge Morales Master

              Hi Tung,

              Then you have some options:

              • To do ContentBasedRouting based on the method being invoked. (It is set as "org.switchyard.operationName").
              • Have different implementations for you component, each for every method.

               

              First option is the easiest one, so you could do something like:

               

              from("switchyard://PersonManagement")

              .choose()

              .when(header("org.switchyard.operationName").isEqualTo("save"))

                                  .to("switchyard://sqlPersistSomething....")

                              .when(header("org.switchyard.operationName").isEqualTo("delete"))

                                  .to("switchyard://sqlDeleteSomething...")

                              .otherwise()

                                  .to("direct:error");

              • 4. Re: How to make Camel filter in SwitchYard component
                Tung Tran Newbie

                Thank you very much, Jorge. But where can I find the properties such as "org.switchyard.operationName". Is the anywhere I can find them?

                • 5. Re: How to make Camel filter in SwitchYard component
                  Jorge Morales Master

                  Hi,

                  It is difficult to say. These properties are set internally by the engine. You can see them if you enable message tracing for the execution of a composite or debugging. I do not think there is documentation around these variables. I would encourage you to open a JIRA for a document with that info.

                   

                  Keep in mind I'm a user not a SwitchYard developer ;-)