Apache Camel,从另一个路由调用一条路由

时间:2016-03-17 10:00:04

标签: apache-camel jbossfuse

我在一个骆驼语境中有两条路线。

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <propertyPlaceholder location="classpath:facebook.properties"
            id="properties" />
        <route>
            <from uri="jetty:http://0.0.0.0:8765/getLikes" />
            <to uri="facebook" />
        </route>

        <route>
            <from uri="facebook://userLikes?oAuthAppId={{oAuthAppId}}&amp;oAuthAppSecret={{oAuthAppSecret}}&amp;oAuthAccessToken={{oAuthAccessToken}}" />
            <log message="The message contains ${body}" />
        </route>
    </camelContext>

在第二个路线中我使用facebook组件。 我想打电话给http://localhost:8765/getLikes并从第二条路线获得所有来自facebook的喜欢。但第一条路线找不到第二条

1 个答案:

答案 0 :(得分:2)

您必须使用直接http://camel.apache.org/direct)或 seda http://camel.apache.org/seda.html)等组件:

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <propertyPlaceholder location="classpath:facebook.properties"
            id="properties" />
        <route>                
            <from uri="jetty:http://0.0.0.0:8765/getLikes" />
            <to uri="direct:facebook" />
        </route>

        <route>
            <from uri="direct:facebook" />
            <!-- Maybe you need to set some headers here -->
            <to uri="facebook://userLikes?oAuthAppId={{oAuthAppId}}&amp;oAuthAppSecret={{oAuthAppSecret}}&amp;oAuthAccessToken={{oAuthAccessToken}}" />
            <log message="The message contains ${body}" />
        </route>
    </camelContext>

此链接http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html对您也有帮助。