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
rss spring-integration
add a comment |
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
rss spring-integration
add a comment |
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
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 at 16:59
Thomas A.
31
31
add a comment |
add a comment |
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.
- 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 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
add a comment |
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()
.
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
add a comment |
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.
- 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 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
add a comment |
up vote
0
down vote
accepted
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 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
add a comment |
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.
- 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 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
add a comment |
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
add a comment |
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()
.
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
add a comment |
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()
.
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
add a comment |
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()
.
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 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
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 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
add a comment |
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