Web services 使用spring的apachecamel web服务
我对阿帕奇骆驼很陌生,请不要介意我在任何时候都错了。 关于阿帕奇骆驼,我有两个问题Web services 使用spring的apachecamel web服务,web-services,apache-camel,integration,Web Services,Apache Camel,Integration,我对阿帕奇骆驼很陌生,请不要介意我在任何时候都错了。 关于阿帕奇骆驼,我有两个问题 在internet中的apache camel示例中,我只能看到命中一个web服务并将其路由到另一个web服务。如何调用Web服务、解组对象并在应用程序中使用,而不是路由到另一个应用程序 在示例中,为了调用camel上下文,我们必须调用 CamelContext=新的DefaultCamelContext() context.start() 及 context.stop() 在spring中是否有其他方法可以在应
如果有人能向我指出任何可以帮助我的资源,如pdf或网站,这将非常有帮助。只需将camel上下文声明为普通bean即可
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<package>my.package.with.routebuilders</package>
</camelContext>
至第一:
您可以创建一个处理器来处理来自Web服务的数据。您的处理器可以连接到路由生成器。您的routebuilder可能如下所示:
public class MyRouteBuilder extends SpringRouteBuilder {
@Autowired
private MyProcessor myProcessor;
@Override
public void configure() throws Exception {
from("xy")
.process(myProcessor);
}
}
您的处理器:
public class MyProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Message msg = exchange.getIn();
//do something with your message
}
}
当然,您必须创建处理器的bean。您可以对其进行注释,并启用spring组件扫描或在spring-context.xml中定义它:
<bean class="com.package.of.your.processor.MyProcessor" />
至第二:
就像@Sergey说的那样。您可以在spring配置中实例化您的上下文。
在我的示例中,您的springconfig如下所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="com.package.of.your.processor.MyProcessor" />
<bean id="myRouteBuilder" class="com.package.of.your.routbuilder.MyRouteBuilder" />
<camel:camelContext id="camelContext">
<camel:routeBuilder ref="myRouteBuilder" />
</camel:camelContext>
</beans>
我仍然必须提供camelContext.start()和camelContext.stop()方法吗?或者我可以直接使用上下文?没有必要。驼峰上下文将从spring上下文开始,并在spring上下文停止时停止
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="com.package.of.your.processor.MyProcessor" />
<bean id="myRouteBuilder" class="com.package.of.your.routbuilder.MyRouteBuilder" />
<camel:camelContext id="camelContext">
<camel:routeBuilder ref="myRouteBuilder" />
</camel:camelContext>
</beans>