Apache Camel 如何从 sql 组件访问 Header 值

Apache Camel How do I access the Header values from an sql component

我正在尝试使用 属性 header.CamelSqlRowCount 打印 sql 组件选择的行数。但是,该值变空了。 我添加了另一个 post 中提到的跟踪来检查 header 值,并且只打印了 breadcrumbId。谁能告诉我我做错了什么?

骆驼路线

        <endpoint id="sqlComponent" uri="sql:${sql.pollerQuery}?dataSource=DataSource&amp;consumer.delay=60000&amp;consumer.useIterator=false"/>
    <route id="root">
        <from ref="sqlComponent"/>
        <log message="Received ${header.CamelSqlRowCount} records from the poller query"/>
        <log message="Message Body= ${body}"/>
    </route>

记录的跟踪如下

DEBUG 2017-11-16 18:01:00 [Camel (camel-1) thread #0 - sql://SELECT%20ID%20FROM%20TABLE%20WHERE%20PUBLISHED%20=%20'N'] Executing query: SELECT ID FROM TABLE WHERE PUBLISHED = 'N'
INFO  2017-11-16 18:01:01 [Camel (camel-1) thread #0 - sql://SELECT%20ID%20FROM%20TABLE%20WHERE%20PUBLISHED%20=%20'N'] ID-MyMachine >>> (root) from(sql://SELECT%20ID%20FROM%20TABLE%20WHERE%20PUBLISHED%20=%20'N'?consumer.delay=60000&consumer.useIterator=false&dataSource=odsDataSource) --> log[Received ${header.CamelSqlRowCount} records from the poller query] <<< Pattern:InOnly, Headers:{breadcrumbId=ID-MyMachine}, BodyType:java.util.ArrayList, Body:[{ID=1}, {ID=2}, {ID=3}, {ID=4}, {ID=5}]
INFO  2017-11-16 18:01:01 [Camel (camel-1) thread #0 - sql://SELECT%20ID%20FROM%20TABLE%20WHERE%20PUBLISHED%20=%20'N'] Received  records from the poller query
INFO  2017-11-16 18:01:01 [Camel (camel-1) thread #0 - sql://SELECT%20ID%20FROM%20TABLE%20WHERE%20PUBLISHED%20=%20'N'] ID-BLRKEC381989D-52624-1510835442422-0-2 >>> (root) log[Received ${header.CamelSqlRowCount} records from the poller query] --> log[Message Body= ${body}] <<< Pattern:InOnly, Headers:{breadcrumbId=ID-MyMachine}, BodyType:java.util.ArrayList, Body:[{ID=1}, {ID=2}, {ID=3}, {ID=4}, {ID=5}]
INFO  2017-11-16 18:01:01 [Camel (camel-1) thread #0 - sql://SELECT%20ID%20FROM%20TABLE%20WHERE%20PUBLISHED%20=%20'N'] Message Body= [{ID=1}, {ID=2}, {ID=3}, {ID=4}, {ID=5}]

骆驼版本 - 2.15.1

这个header没有在消费者上设置,只在生产者上设置。您的邮件大小 body 列表大小。您可以在 Apache Camel 上记录一个 JIRA 票证,要求将此 header 也包含在消费者中。