如何使用同一CamelContext在多个罐子上同一场战争 [英] How to use same CamelContext in multiple jar on the same war

查看:186
本文介绍了如何使用同一CamelContext在多个罐子上同一场战争的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用骆驼2.16.2,我需要用一个CamelContext多个罐子,因为我需要让所有的骆驼路由器在一个CamelContext。因此,我的战争将所有这些罐子作为Maven工件。

请让我知道我该如何处理上述场景?

修改

只是为了更多地讨论上面的问题。
在我的战争myApp.war,我已经初始化CamelContext。有三个罐子myApp1.jar,myApp2.jar和myApp3.jar。每个瓶子都有单独定义它自己的路由器。


  1. 如何启动路由器中的每个罐子?

  2. 我可以使用注射到每个路由器相同CamelContext?

  3. 如果我无法通过罐处理,是否有可能与多个战争(myApp1.war,myApp2.war和myApp3.war),每个战争来实现具有不同camelContext和交流,从主战这些路由器(myApp.war )?


解决方案

之后做一些研究找到了一种方法来实现这一点。逸岸,我们可以使用相同的CamelContext在不同的罐子,因为所有的罐子都在同一个战争(Web容器)。

我们可以用 Apache的骆驼2.16.2 骆驼CDI轻松实现。如果您使用wildfly部署你的战争,那么你可能需要添加骆驼补丁。下载href=\"https://github.com/wildfly-extras/wildfly-camel/releases/tag/3.3.0\" rel=\"nofollow\"> wildfly 9.0.2 PACH 的

步骤如下。

在你的战争创建一个servlet或restService和注入camelContext。

  @Inject
@ContextName(CDI上下文)
私人CamelContext camelctx;

在下面标注的jar创建一个路由器。

  @Startup
@ApplicationScoped
公共类MyJRouteBuilder扩展RouteBuilder {

在配置方法添加

  @覆盖
公共无效配置()抛出异常{
    从(直接:startTwo)routeId(MyJRouteBuilder)。
    .bean(新SomeBeanThree());
}

在您的罐子创建一个引导程序类,并添加路由器

  @Singleton
@启动
公共类自举{私人CamelContext camelctx;@PostConstruct
公共无效的init()抛出异常{
    camelctx.addRoutes(新MyJRouteBuilder());
}

添加您的罐子作为战争的pom.xml神器。一旦你部署的战争中,你可以看到MyJRouteBuilder是Registred在 CDI上下文 CamelContext 。所以现在你可以访问你的路由器的任何地方你想要的。

希望这会非常有用的人谁拥有了同样的问题我有什么。

I'm using the camel 2.16.2 and I need to use the one CamelContext across multiple jars as I need to have all the Camel Routers in to one CamelContext. So my war will have all those jars as maven artifacts.

Please let me know how do I handle above scenario?

Edit

Just to elaborate more on above question. In my war myApp.war, I have initialized the CamelContext. There are three jars myApp1.jar, myApp2.jar and myApp3.jar. Each jar has it own routers defined separately.

  1. How do I start the routers in each jar ?
  2. Can I use the same CamelContext injected to each routers?
  3. If I cannot handle through jars, is it possible to implement with multiple war (myApp1.war, myApp2.war and myApp3.war) and each war having different camelContext and communicate to those routers from the main war (myApp.war) ?

解决方案

After doing some research found a way to implement this. Infact we can use the same CamelContext across different jars as all jars are in the same war (Web Container).

We can implement easily with Apache Camel 2.16.2 with camel CDI. If you're using wildfly to deploy your war then you may need to add the camel patch. Download the the wildfly 9.0.2 pach

Steps are Given Below.

In your war create a servlet or restService and Inject the camelContext.

@Inject
@ContextName("cdi-context")
private CamelContext camelctx;

Create a router in the jar with below annotation.

@Startup
@ApplicationScoped
public class MyJRouteBuilder extends RouteBuilder {

In Configure method add

@Override
public void configure() throws Exception {
    from("direct:startTwo").routeId("MyJRouteBuilder")
    .bean(new SomeBeanThree());
}

Create a BootStrap Class in your jar and add the Router

@Singleton
@Startup
public class BootStrap {

private CamelContext camelctx;

@PostConstruct
public void init() throws Exception {   
    camelctx.addRoutes(new MyJRouteBuilder());
}

Add your jar as a artifact in the war pom.xml. Once you deploy the war you can see MyJRouteBuilder is Registred in the cdi-context CamelContext. So now you can access your Router anywhere you want.

Hope this would useful anyone who has the same issue what I had.

这篇关于如何使用同一CamelContext在多个罐子上同一场战争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆