How to dynamically unregister IntegrationFlow of IntegrationFlowContext if Feed inbound adapter throw an exception?
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
add a comment |
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
add a comment |
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
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
rss spring-integration
asked Nov 10 '18 at 16:59
Thomas A.Thomas A.
82
82
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Add an errorChannel
to the poller
to get the exception.
There are two ways to unregister the flow.
- Keep a reference to the registration and call
destroy()
on it. context.remove(flowId)
(which is what #1 does)
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
add a comment |
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()
.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Add an errorChannel
to the poller
to get the exception.
There are two ways to unregister the flow.
- Keep a reference to the registration and call
destroy()
on it. context.remove(flowId)
(which is what #1 does)
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
add a comment |
Add an errorChannel
to the poller
to get the exception.
There are two ways to unregister the flow.
- Keep a reference to the registration and call
destroy()
on it. context.remove(flowId)
(which is what #1 does)
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
add a comment |
Add an errorChannel
to the poller
to get the exception.
There are two ways to unregister the flow.
- Keep a reference to the registration and call
destroy()
on it. context.remove(flowId)
(which is what #1 does)
Add an errorChannel
to the poller
to get the exception.
There are two ways to unregister the flow.
- Keep a reference to the registration and call
destroy()
on it. context.remove(flowId)
(which is what #1 does)
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
add a comment |
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
add a comment |
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()
.
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
add a comment |
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()
.
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
add a comment |
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()
.
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()
.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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