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

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

问题描述

我点击数据库获得 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);
                        }
                    })

现在我可以在聚合器中做同样的事情,我可以用上面的代码丰富原始代码并返回.

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 (1) 中编写了 JDBC 代码.另一个区别是您管理迭代以获取每位员工的详细数据.这也意味着您需要自己进行任何错误处理(如果处理在迭代过程中中止,如何恢复等).

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).

解决这个用例的 Camel 方法是:

The Camel way to solve this use case is:

  1. JDBC 调用以获取员工
  2. Splitter 将员工列表拆分为单独的消息(创建"迭代")
  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 Beans.

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

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

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