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











up vote
0
down vote

favorite












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


























    up vote
    0
    down vote

    favorite












    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
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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 at 16:59









      Thomas A.

      31




      31
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          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 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 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 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 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 at 19:23


















          up vote
          0
          down vote













          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 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',
          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








          up vote
          0
          down vote



          accepted










          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 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 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 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 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 at 19:23















          up vote
          0
          down vote



          accepted










          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 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 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 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 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 at 19:23













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          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 at 20:48









          Gary Russell

          76.4k64166




          76.4k64166












          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 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 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 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 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 at 19:23


















          • Thanks Gary. I think the error channel of the poller is what I need.
            – Thomas A.
            Nov 12 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 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 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 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 at 19:23
















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




          Thanks Gary. I think the error channel of the poller is what I need.
          – Thomas A.
          Nov 12 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 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 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 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 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 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 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 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 at 19:23












          up vote
          0
          down vote













          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 at 9:52















          up vote
          0
          down vote













          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 at 9:52













          up vote
          0
          down vote










          up vote
          0
          down vote









          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 at 20:48









          Artem Bilan

          62.1k84567




          62.1k84567












          • 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 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 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 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 at 9:52


















           

          draft saved


          draft discarded



















































           


          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

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values