How to dynamically unregister IntegrationFlow of IntegrationFlowContext if Feed inbound adapter throw an exception?

Viewed 369

I inserted some feeds in a MongoDB collection.

In my Spring Integration application, I use MongoDB inbound adapter to read periodically the feeds collection and check if a feed is enabled or not.

If a fedd is enabled and not yet in the IntegrationFlowContext, I register it.

Once a feed IntegrationFlow is created, it reads the feed periodically to extract articles.

The problem is, if the Feed inbound adapter throw an exception, for example because the URL is not valid anymore, how can I catch this exception (there is no error channel available) and unregister the feed of the IntegrationFlowContext ?

I created a Gist to expose my problem https://gist.github.com/OttoDev/63d31f301bdd777694f4331cab782913

2 Answers

Why do you need to register it dynamically? There is just enough to handle disable/enable via start()/stop() lifecycle control. Anyway the Inbound Channel Adapter can be configured with the errorChannel see the second arg of the IntegrationFlows.from().

Add an errorChannel to the poller to get the exception.

There are two ways to unregister the flow.

  1. Keep a reference to the registration and call destroy() on it.
  2. context.remove(flowId) (which is what #1 does)
Related