I am trying to implement BeanPostProcessor to return my own JdbcPollingChannelAdapter that will help me to add some logging and know about polling activity. I have some code below, please help to complete this or if there is a better way.
Thanks
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;
}
}
The
JdbcPollingChannelAdapter
is aMessageSource<?>
and it is a component to be used from activeendpoint
-SourcePollingChannelAdapter
, which has this code:So, isn't it enough for you to just configure
org.springframework.integration.endpoint.SourcePollingChannelAdapter
logging category?From other side, there are no stops to use your custom
MessageSource<?>
implementation andBeanPostProcessor
is really an overhead. You just need to configure yourCustomAdapter
as a generic<bean>
and use it from another generic bean definition -SourcePollingChannelAdapterFactoryBean
.Right, with that customization you lose the Spring Integration XML power. But who said that XML is a panacea - Spring Integration Java DSL?
UPDATE
Since you have a custom
MessageSource<?>
you can use it directly from:Any protocol-specific
<*:inbound-channel-adapter>
is just for convenience, but they all do them same as default one.