Apache的骆驼MDC从车身添加字段 [英] Apache Camel MDC add field from Body

查看:166
本文介绍了Apache的骆驼MDC从车身添加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Apache的骆驼工作,并希望某些键添加到使用MDC我的日志。我通过官方骆驼MDC记录文档这是pretty大去了。我可以登录我routeId的毫不费力。我还需要从骆驼的身体添加一个字段。

I am working with apache camel and would like to add certain keys to my logs using MDC. I went through the official Camel MDC Logging documentation which is pretty great. I am able to log my routeId's without much effort. I also need to add a field from Camel's Body.

最坏的情况,我可以在所有路由手动添加这一点,但我想知道如果可能从身体处于比较容易的方式将字段添加到MDC?

Worst case scenario I can add this manually in all routes, but I was wondering if its possible to add fields from body to MDC in a easier fashion?

任何想法是AP preciated。我真的希望能够做到这一点,而不必去到每一个路线并加入一个衬垫。

Any ideas are appreciated. I would really like to be able to do this without having to go into every route and adding a one liner.

更新:

在实现我的项目定制MDCUnitOfWork工厂。我能看到CustomUnitOfWorkFactory创建我CustomUnitOfWork,然后设置MDC值。

Implemented a custom MDCUnitOfWork and Factory in my project. I am able to see the CustomUnitOfWorkFactory creating my CustomUnitOfWork which is then setting the MDC values.

不过,我注意到这只是发生在路由的开始。

However I noticed this only happens in the beginning of the route.

在我的使用情况下,我是一个轮询亚马逊SQS作为我的第一条路线。我这里不具备所需的信息。在第一条路线我建立我的背景下,并设置为骆驼身上这也正是我的信息,我需要MDC设置驻留。

In my use case, I am Polling an Amazon SQS as my first route. I do not have the required information here. In the first route I build my Context and set that to Camel body which is where my information that I need to set in MDC resides.

是否有可能第二条路之前创建的UnitOfWork呢?

Is it possible to create UnitOfWork before second route as well?

推荐答案

您可以配置自定义 UnitOfWorkFactory 以创建一个自定义的的UnitOfWork ,它扩展了 MDCUnitOfWork ,在这里你可以到MDC添加自定义的信息。

You can configure a custom UnitOfWorkFactory to create a custom UnitOfWork that extends the MDCUnitOfWork, where you can add custom information to MDC.

您可以从Java上CamelContext配置UnitOfWorkFactory或XML只需添加一个<豆> 和骆驼检测,并使用它

You can configure the UnitOfWorkFactory on CamelContext from Java or in XML just add a <bean> and Camel detects and uses it

这篇关于Apache的骆驼MDC从车身添加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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