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

  • How to add logging to a jdbc pollar adapter


    Code:
    <int-jdbc:inbound-channel-adapter
    query="${some.select.query}"
    channel="responseChannel"
    max-rows-per-poll="100"
    data-source="myDataSurce"
    auto-startup="true"
    row-mapper="myDataMapper" >
    <int-poller fixed-rate="60000">
    <int:transactional/>
    </int-poller>
    </int-jdbc:inbound-channel-adapter>
    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

    Code:
    org.springframework.integration.endpoint.SourcePollingChannelAdapter
    and you'll get log messages like...

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

    and

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

    Comment


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

      Comment


      • #4
        I have not been able to wire this together, any help would be appreciated. I have below code as of now.
        Code:
        public class CustomAdapter extends JdbcPollingChannelAdapter {
            
            private final static Logger logger = LoggerFactory.getLogger(CustomAdapter .class);
            
            public CustomJdbcPollingChannelAdapter(DataSource dataSource, String selectQuery)
            {
                super(dataSource, selectQuery);        
            }
            
            @Override
            public Message<Object> receive()
            {
                Message<Object> polledData =  super.receive();
                if(polledData == null || polledData.getPayload() == null)
                logger.info("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.
                logger.info(bean+"..................."+beanName);
                if(bean instanceof org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean)
                {
                    //SourcePollingChannelAdapterFactoryBean bean = (SourcePollingChannelAdapterFactoryBean)bean;
                    //bean...??
                    return bean;
                }
                else
                {
                 return bean;
                }
                */
                return bean;
            }
        
            
            public Object postProcessBeforeInitialization(Object bean, String beanName)throws BeansException
            {
                //logger.info(bean+"................................................."+beanName);
                return bean;
            }
        
        }
        Please also let me know if there is a better way.

        Thank You very much

        Comment


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

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