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










1














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










share|improve this question


























    1














    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










    share|improve this question
























      1












      1








      1







      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










      share|improve this question













      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







      rss spring-integration






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 '18 at 16:59









      Thomas A.Thomas A.

      82




      82






















          2 Answers
          2






          active

          oldest

          votes


















          0














          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)





          share|improve this answer




















          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 '18 at 9:56










          • Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
            – Thomas A.
            Nov 12 '18 at 15:00










          • You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
            – Gary Russell
            Nov 12 '18 at 15:04










          • I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
            – Thomas A.
            Nov 12 '18 at 17:31










          • Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
            – Gary Russell
            Nov 12 '18 at 19:23


















          0














          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().






          share|improve this answer




















          • Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
            – Thomas A.
            Nov 12 '18 at 9:52










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241275%2fhow-to-dynamically-unregister-integrationflow-of-integrationflowcontext-if-feed%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          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)





          share|improve this answer




















          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 '18 at 9:56










          • Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
            – Thomas A.
            Nov 12 '18 at 15:00










          • You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
            – Gary Russell
            Nov 12 '18 at 15:04










          • I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
            – Thomas A.
            Nov 12 '18 at 17:31










          • Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
            – Gary Russell
            Nov 12 '18 at 19:23















          0














          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)





          share|improve this answer




















          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 '18 at 9:56










          • Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
            – Thomas A.
            Nov 12 '18 at 15:00










          • You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
            – Gary Russell
            Nov 12 '18 at 15:04










          • I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
            – Thomas A.
            Nov 12 '18 at 17:31










          • Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
            – Gary Russell
            Nov 12 '18 at 19:23













          0












          0








          0






          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)





          share|improve this answer












          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)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 '18 at 20:48









          Gary RussellGary Russell

          79.4k74471




          79.4k74471











          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 '18 at 9:56










          • Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
            – Thomas A.
            Nov 12 '18 at 15:00










          • You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
            – Gary Russell
            Nov 12 '18 at 15:04










          • I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
            – Thomas A.
            Nov 12 '18 at 17:31










          • Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
            – Gary Russell
            Nov 12 '18 at 19:23
















          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 '18 at 9:56










          • Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
            – Thomas A.
            Nov 12 '18 at 15:00










          • You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
            – Gary Russell
            Nov 12 '18 at 15:04










          • I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
            – Thomas A.
            Nov 12 '18 at 17:31










          • Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
            – Gary Russell
            Nov 12 '18 at 19:23















          Thanks Gary. I think the error channel of the poller is what I need.
          – Thomas A.
          Nov 12 '18 at 9:56




          Thanks Gary. I think the error channel of the poller is what I need.
          – Thomas A.
          Nov 12 '18 at 9:56












          Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
          – Thomas A.
          Nov 12 '18 at 15:00




          Adding an error channel to the poller works fine. Is there a way to either customize the exception (and its content) thrown to the error channel or to add a new entry in the headers of the message to indicate what feed is causing the exception ?
          – Thomas A.
          Nov 12 '18 at 15:00












          You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
          – Gary Russell
          Nov 12 '18 at 15:04




          You would have to add .enrichHeaders() to the feed flow to add a header; then in the error flow; payload.failedMessage.headers['myHeader'].
          – Gary Russell
          Nov 12 '18 at 15:04












          I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
          – Thomas A.
          Nov 12 '18 at 17:31




          I tried to add my custom header this way : IntegrationFlows .from(Feed.inboundAdapter(new URL(feedUrl), feedName).metadataStore(metadataStore), e -> e.poller(...).errorChannel(feedErrorQueueChannel))) .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("feedName", feedName)) .channel(feedQueueChannel) .get());. But this does not work, my failed message is null. However, errorMessage.getHeaders() give me two headers, id and timestamp.
          – Thomas A.
          Nov 12 '18 at 17:31












          Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
          – Gary Russell
          Nov 12 '18 at 19:23




          Don't put code in comments; it's unreadable; edit the question instead. failedMessage is null; Oh; right, there is no message yet if the feed is down. The easiest way would be to have an errorChannel flow for each feed and put the enricher there.
          – Gary Russell
          Nov 12 '18 at 19:23













          0














          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().






          share|improve this answer




















          • Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
            – Thomas A.
            Nov 12 '18 at 9:52















          0














          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().






          share|improve this answer




















          • Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
            – Thomas A.
            Nov 12 '18 at 9:52













          0












          0








          0






          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().






          share|improve this answer












          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().







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 '18 at 20:48









          Artem BilanArtem Bilan

          64.3k84668




          64.3k84668











          • Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
            – Thomas A.
            Nov 12 '18 at 9:52
















          • Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
            – Thomas A.
            Nov 12 '18 at 9:52















          Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
          – Thomas A.
          Nov 12 '18 at 9:52




          Thanks Artem. I need to register feeds dynamically because new feeds could be added to my MongoDB collection and I want to detect this new feeds periodically. How could I use start and stop methods in my case ?
          – Thomas A.
          Nov 12 '18 at 9:52

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241275%2fhow-to-dynamically-unregister-integrationflow-of-integrationflowcontext-if-feed%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Edmonton

          Crossroads (UK TV series)