3

I am trying to print the number of rows selected by an sql component using the property header.CamelSqlRowCount. However the value is coming empty. I added trace as mentioned in another post to check the header values and only breadcrumbId is getting printed. Can anyone tell me if I am doing anything wrong?

Camel Route

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

The trace logged is below

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}]

Camel version - 2.15.1

Sarun
  • 71
  • 7
  • 1
    did u check this https://stackoverflow.com/questions/18572129/apache-camel-how-to-get-header-attributes-from-sql-component May be you get some hint – pvpkiran Nov 17 '17 at 09:42
  • Try with a newer version – Claus Ibsen Nov 17 '17 at 12:09
  • yes, i had checked that link. The issue there was due to multicast. I had a split component earlier in my route. After checking that, I removed the split component and made a simple route as shown above to verify that the issue is not due to the split component. – Sarun Nov 17 '17 at 12:15
  • didn't work with camel version 2.20.0 either – Sarun Nov 17 '17 at 12:47

1 Answers1

5

This header is not set on the consumer, only on the producer. You have the size on the message body list size. You can log a JIRA ticket at Apache Camel to ask for this header to be included by the consumer as well.

Claus Ibsen
  • 52,841
  • 7
  • 41
  • 58
  • Thanks for the details. Replaced the property ${header.CamelSqlRowCount} with ${body.size()} to get the count. – Sarun Nov 20 '17 at 05:49