In order to use camel to invoke method of a service like in WCF we can use camel methods bean invocations.
Construct a bean with methods :
For an example :
1: package org.apache.camel.example.console;2:3: public class myService {4: public void SayHello (String pMsg)5: {6:7: System.out.print( "Hello:" + pMsg);8: }9: public void SayGoodBy (String pMsg)10: {11: System.out.print("Goodby:" + pMsg);12: }13:14: }
The camel route:
1: CamelContext context = new DefaultCamelContext();2: context.addRoutes(new RouteBuilder() {3: public void configure() {4: from("stream:in?promptMessage=Enter something please :").5: bean(myService.class, "SayHello");
The SayHello method will be invoked.
selecting the bean method using an header.
1: CamelContext context = new DefaultCamelContext();2: context.addRoutes(new RouteBuilder() {3: public void configure() {4: from("stream:in?promptMessage=Enter something please :").5: setHeader("CamelBeanMethodName", constant("SayGoodBy")).6: bean(myService.class);
And the Result is invoking the SayGoodBy method:
Enter something please :This is a test
Goodby:This is a test
אין תגובות:
הוסף רשומת תגובה