1

I'm using spring integration aggregator and MessageGroupStoreReaper but somehow the errors are not reaching global errorChannel.

    <int:aggregator id="agg"
                    ref="MyMsgsAggregator"
                    input-channel="myAggInputChannel"
                    output-channel="processInputChannel"
                    discard-channel="errorChannel"
                    method="aggMessages"
                    message-store="messageGroupStore"
                    send-partial-result-on-expiry="true"
                    expire-groups-upon-completion="true" />
                    
<bean id="messageGroupStore" class="org.springframework.integration.store.SimpleMessageStore" />

<task:scheduled-tasks>
        <task:scheduled ref="multipartAggregatorReaper" method="run" fixed-rate="5000" />
</task:scheduled-tasks>

If there is any exception post "processInputChannel" ( e.g partial result on expiry) then exception is not reaching global "errorChannel".

Even I tried replacing task-scheduled job to inbound channel adapter( as suggested by @Gary) with poller but still it didn't work :

<int:inbound-channel-adapter channel="reaperChannel" ref="MyMsgsAggregator" method="triggerReaper"> 
<int:poller error-channel="**errorChannel**" fixed-rate="5000">         
</int:poller>

</int:inbound-channel-adapter>

Pls suggest

Thanks

Abdul Mohsin
  • 105
  • 7

1 Answers1

0

Your problem is here: send-partial-result-on-expiry="true". This option is indeed mutually exclusive with the discard-channel:

protected void expireGroup(Object correlationKey, MessageGroup group, Lock lock) {
    ...
    if (this.sendPartialResultOnExpiry) {
        ...
        completeGroup(correlationKey, group, lock);
    }
    else {
        ...
        group.getMessages()
                .forEach(this::discardMessage);
    }
    ...
}

So, that's not a surprise that your messages after reaping go to the processInputChannel, not an errorChannel.

Also, the discardChannel is not about errors. The exception is not thrown in case of discarding when we reap and an ErrorMessage is not sent from there. Everything single message from the reaped group is sent as regular one into that configured discardChannel.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Hi Artem , thanks for the reply . The problem is not related to "discard channel" . What I'm expecting is the normal flow in case of any exception ( partial or with complete aggregation ) .. any exception post partial/complete aggregation from "processInputChannel" is not going to global error channel. – Abdul Mohsin Mar 05 '21 at 18:36
  • I have also tried adding the errorChannel header post channel "processInputChannel" as suggested in the spring docs but that also didn't work.. the only thing which is different on this flow as compared to other spring integration flow is the triggering of MessageGroupStoreReaper through task scheduler ( even I tried the inbound adapter with Poller but that also didn't work) – Abdul Mohsin Mar 05 '21 at 18:39
  • OK. You should place a `` behind that `processInputChannel`: ` `. So, all the sub-flow, independently of the producer thread is going to be covered by the same error handling mechanism. – Artem Bilan Mar 05 '21 at 18:44
  • Currently I have a splitter consuming the messages from "processInputChannel" , any exception thrown by splitter are not going to "errorChannel" – Abdul Mohsin Mar 05 '21 at 18:47
  • 1
    Well, another way is advice that splitter with the `ExpressionEvaluatingRequestHandlerAdvice`: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#message-handler-advice-chain. You don't get errors there because you `TaskScheduler` is not enhanced with the `MessagePublishingErrorHandler`. – Artem Bilan Mar 05 '21 at 18:52
  • Thanks Artem .. I'll try your suggestion to include gateway in-between.. but what I feel is that there must be some mechanism to re-register that global error functionality which is missing due to that separate thread triggering the reaper.. – Abdul Mohsin Mar 05 '21 at 18:53
  • Yes I have used that "ExpressionEvaluatingRequestHandlerAdvice" and resolved this issue .. but wanted to check if there is any better way available to handle such cases.. – Abdul Mohsin Mar 05 '21 at 18:55
  • No, that's not. It's your environment and the Spring Integration has nothing to do with your scheduled tasks. It is really your responsiblity to do with errors whatever you need. There was just no any error channel registered when you run that reaper task. – Artem Bilan Mar 05 '21 at 18:56
  • What case? You start an execution from the scheduled task, so you are responsible to setup error handling over there. Not sure how Spring Integration can guess what to do with those tasks... – Artem Bilan Mar 05 '21 at 18:57
  • Then I'll suggest we should have some better mechanism to run the reaper to integrate it better with spring-integration so that it can reuse the global context things (e.g errorChannel) – Abdul Mohsin Mar 05 '21 at 18:59
  • I think the question is .. how in the aggregation scenarios ( partial / complete/expire etc) we can use the same "errorChannel" funtionality.. – Abdul Mohsin Mar 05 '21 at 19:02
  • 1
    See also `setForceReleaseAdviceChain()` on the `AbstractCorrelatingMessageHandler` (might not be available for XML config though)... Well, I see your point. Need to think more, but it is indeed depend how you initiate the process. We probably just may have an `errorChannel` option on the aggregator in the end to handle individual errors for every group. Because right now it looks like one expired and errouness group is going to skip all the rest reaped. It is really better to have an error handling on that splitter: look at it as a regular Java loop and each item handling. – Artem Bilan Mar 05 '21 at 19:08
  • Thanks got your point , I also saw your another suggestion on similar issue - https://stackoverflow.com/questions/25999096/spring-integration-how-to-handle-exceptions-in-services-after-an-aggregator?rq=1 – Abdul Mohsin Mar 05 '21 at 19:12
  • Again many thanks to your team , this wonderful framework is helping us a lot in integrations. – Abdul Mohsin Mar 05 '21 at 19:14
  • 1
    Wow! I already suggested an `errorChannel` for the aggregator :smile:! Please, raise a GH issue and we will see with Gary what we can do with that. Thank you for your patience! – Artem Bilan Mar 05 '21 at 19:18
  • As suggested raised a GH issue : #3504 (https://github.com/spring-projects/spring-integration/issues/3504) – Abdul Mohsin Mar 05 '21 at 19:51