无法创建路由,原因是:找不到scheme:activemq的组件

时间:2014-01-07 04:54:11

标签: web-services cxf apache-karaf osgi-bundle apache-servicemix

Servicemix专家需要一些帮助。

我在apache servicemix中部署了一个Web服务。我从在同一台机器上的tomcat上部署的Web应用程序中点击这个Web服务。我想将自定义消息从Web服务发送到activemq:queue。

网络服务代码:

@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";

    }


}

我想将 userId isbn 从网络服务发送到testqueue。这个Web服务使用apache cxf框架实现。

下面是我的beans.xml,它放在 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>

我已经在servicemix中将上面的示例应用程序部署为maven-bundle-plugin。当我点击上面的网络服务时,它会给我以下错误:

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 

1 个答案:

答案 0 :(得分:0)

您正在混合使用CXF独立版和Camel但未加入这两种技术。 您可以使用Camel完全编写服务(使用camel-rest或camel-cxf组件从端点更改)。 要启用Camel发送消息,需要添加依赖项org.apache.activemq:activemq-camel:5.10.0

另一方面,您可以使用spring-jms项目和Spring JMSTemplate将消息发送到activemq,而不是使用Camel。见http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/jms.html