Apache Camel:带有示例的Message Translator和Content Enricher有什么区别? [英] Apache Camel: What is difference between Message Translator and Content Enricher with Example?

查看:86
本文介绍了Apache Camel:带有示例的Message Translator和Content Enricher有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我命中数据库得到10名员工;在每位员工的基础上,我访问了另一个数据库并获取了一些信息并将其连接起来.

I hit database get 10 employees; on base of each employee i hit another database and fetch some information and concatenate the same.

据我了解,可以在.process()或.enrich()中完成(使用聚合器)

As per my understanding, It can be done either in .process() or in .enrich() (using aggregator)

                    .to("jdbc:masterdata?outputClass=com.diavry.integrator.Employee")
                    .to("log:?level=INFO&showBody=true")                    
                    .process(e -> { 
                        List<Employee> eiEmployees = (List<Employee>) e.getIn().getBody(List.class);

                        for (Employee employee : eiEmployees) {

                            PreparedStatement statement = otherDbConnection.prepareStatement(sql);
                            statement.setString(1, employee.getUserid());
                            statement.setString(2, employee.getCompanyid());
                            resultSet = statement.executeQuery();
                            if (resultSet.next()) {
                                legalUnitName = resultSet.getString(1);
                            }
                            employee.setOrgstr_unitname(legalUnitName);
                        }
                    })

现在我可以在Aggregator中做同样的事情,在其中我可以用上述代码丰富原始内容并返回.

Now i can do same thing in Aggregator where i can enrich original with above code and return back .

相对于上述用例,我没有区别吗?

I am not getting difference between two in relation to above use case?

推荐答案

好吧,主要区别是您在Processor 中编写了JDBC代码(1).另一个不同之处在于,您可以自己管理迭代以获取每个员工的详细数据.这也意味着您需要自己进行任何错误处理(如果在迭代过程中中止处理如何恢复).

Well, the main difference is that you wrote JDBC code in your Processor (1). Another difference is that you manage the iteration to get detail data for every employee by yourself. That also means that you need to do any error handling by yourself (how to recover if processing aborts in the middle of the iteration etc).

解决此用例的骆驼方法是:

The Camel way to solve this use case is:

  1. 通过JDBC招募员工
  2. 拆分器以将员工列表拆分成单独的消息(创建迭代")
  3. 每位员工的JDBC详细数据调用
  4. 进一步的流程详细信息或汇总所有详细信息 ,具体取决于您的进一步处理需求
  1. JDBC call to get employees
  2. Splitter to split the employee list into individual messages (creates "iteration")
  3. JDBC detail data call per employee
  4. Further process detail message or aggregate all detail messages, depending on your further processing needs

这是骆驼的主要魔法无需编写很多运输级"代码.只需编写一行Camel DSL即可查询数据库,增加JMS使用者和您可以想到的任何其他集成技术.

This is the main magic of Camel! No need to write lots of "transport-level" code. Just write one line of Camel DSL to query a database, ramp up a JMS consumer and any other integration technology you can think of.

当然,所有 EIP都是实现工具,是常见的集成问题.

And of course all the EIPs is implements that are common integration problems.

(1)旁注:我建议删除低级接口Processor,以代替简单的Java Bean .

(1) Side note: I recommend to drop the low-level interface Processor in favor of simple Java Beans.

这篇关于Apache Camel:带有示例的Message Translator和Content Enricher有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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