Announcement Announcement Module
No announcement yet.
How to add logging to a jdbc pollar adapter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add logging to a jdbc pollar adapter

    row-mapper="myDataMapper" >
    <int-poller fixed-rate="60000">
    I am trying to add some logging for production environment (in INFO logging) here, I would like to print received xyz rows or found no rows just to keep things interesting for anyone tailing logs also for inactivity monitors. How can i do this here, i understand that this can be done through advice but somehow finding no reference how to use it with jdbc inbound adapter. Thank you for your help

  • #2
    There's not currently any way to do that with standard code.

    If you only have one polled adapter, you could turn on DEBUG logging for category

    and you'll get log messages like...

    "Poll resulted in Message: [Payload ArrayList contenxt=[... ]"


    "Received no message during the poll, returning 'false'"

    A standard advice in the poller's advice-chain won't really help, because the advice doesn't have access to the message count (just that the poller ran).

    It wouldn't be too difficult to write a BeanPostProcessor that wraps the JdbcPollingChannelAdapter in a proxy that implements MessageSource, so you can access to the results of the receive() method.

    If you need help doing that, let us know

    Another way to monitor inactivity would be an interceptor on "responseChannel" and use a timer (scheduled task) to log a message if you haven't seen a real message after some time. When a real message arrives, log it and cancel the timer, and schedule a new one.


    • #3
      Thanks Gary, i will attempt the BeanPostProcessor solution. Will post here, if i cant make it working, thanks


      • #4
        I have not been able to wire this together, any help would be appreciated. I have below code as of now.
        public class CustomAdapter extends JdbcPollingChannelAdapter {
            private final static Logger logger = LoggerFactory.getLogger(CustomAdapter .class);
            public CustomJdbcPollingChannelAdapter(DataSource dataSource, String selectQuery)
                super(dataSource, selectQuery);        
            public Message<Object> receive()
                Message<Object> polledData =  super.receive();
                if(polledData == null || polledData.getPayload() == null)
      "received no data..............");
                return polledData;
        public class MyPostProcessor implements BeanPostProcessor {
            private final static Logger logger = LoggerFactory.getLogger(MyPostProcessor .class);
            public Object postProcessAfterInitialization(Object bean, String beanName)throws BeansException
                /* not able to figure what goes here for this to work.
                if(bean instanceof org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean)
                    //SourcePollingChannelAdapterFactoryBean bean = (SourcePollingChannelAdapterFactoryBean)bean;
                    return bean;
                 return bean;
                return bean;
            public Object postProcessBeforeInitialization(Object bean, String beanName)throws BeansException
                return bean;
        Please also let me know if there is a better way.

        Thank You very much


        • Artem Bilan
          Artem Bilan commented
          Editing a comment
          Repost, please, you question to the StackOverflow

        • rosadom
          rosadom commented
          Editing a comment
          Ok, sure. Thanks