4

Servicemix expert need some help.

I have a web service deployed in apache servicemix. This web service I hit from web application that is deploying on tomcat on same machine. I want to send custom message from web service to activemq:queue.

web service code:

@Path("/cdlService/")
public class TestService {

    private BundleContext bundleContext;

    @GET
    @Path("/startProcess/{user}/{isbn}")
    @Produces("application/xml")
    public String startProcess(@PathParam("user") long userId, @PathParam("isbn") String isbn){


        System.out.println("id : " + userId + " , isbn : " + isbn);

        CamelContext camelContext = new DefaultCamelContext();

        try {
            camelContext.addRoutes(new RouteBuilder() {

                @Override
                public void configure() throws Exception {

                    from("direct:start").process(new Processor() {

                        @Override
                        public void process(Exchange exchange) throws Exception {

                            System.out.println("in process method");
                            System.out.println(exchange.getExchangeId() + " : " + exchange.getFromRouteId() + " : " + exchange.isFailed());

                        }
                    }).to("activemq:queue:testQueue");

                }


            });

            camelContext.setTracing(true);
            camelContext.start();
        } catch (Exception e1) {
            e1.printStackTrace();

        }finally{

            if(camelContext != null){

                try {
                    camelContext.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

        }



        return "started";

    }


}

I want to send userId and isbn from web service to testqueue. This web service implemented using apache cxf framework.

below is my beans.xml that is placed in resources/META-INF/spring

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
        xmlns:osgi="http://www.springframework.org/schema/osgi"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">


    <jaxrs:server id="testService" address="/test">
        <jaxrs:serviceBeans>
            <ref bean="testSvc"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <bean id="testSvc" class="com.qait.cdl.web.service.TestService"/>

</beans>

I have deployed above sample application in servicemix as bundle by maven-bundle-plugin. when I hit above web service, than it gives me following error :

org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[activemq:queue:testQueue] <<< in route: Route(route1)[[From[direct:start]] -> [process[com.qait.cdl.... because of Failed to resolve endpoint: activemq://queue:testQueue due to: No component found with scheme: activemq 
рüффп
  • 5,172
  • 34
  • 67
  • 113
ved
  • 909
  • 2
  • 17
  • 43

1 Answers1

0

You are mixing CXF standalone and Camel but without joining the two technologies. Either you write your service fully with Camel (change to from endpoint by using camel-rest or camel-cxf components). To enable Camel to send message to you need to add the dependency org.apache.activemq:activemq-camel:5.10.0

On the other hand, instead of using Camel, you can use spring-jms project and the Spring JMSTemplate to send your message to activemq. See http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/jms.html

Mektoub
  • 116
  • 11