2
votes

I'm having some fun testing Spring Integration, so I created this flow (Not very difficult and it works like a charm):

  • A user purchases a book
  • Some transformation is performed
  • A Jms message is sent asynchronously

But I've a question: Do you know if there's any way to print a log if the outbound-channel-adapter fails? I don't care it the JMS publish operation fails because the flow ends returning the correct book payload, but showing a log would be nice, and I think I'm a bit messy with Spring IO error handling.

Thanks in advance!

<si:channel id="purchaseBookInputChannel" />
<si:channel id="purchaseBookReplyChannel" />
<si:channel id="purchaseBookRoutingChannel" />
<si:channel id="purchaseBookJmsInputChannel" />

<si:chain id="purchaseBookChain" input-channel="purchaseBookInputChannel" output-channel="purchaseBookRoutingChannel">
    <si:service-activator ref="bookServiceActivator" method="purchase" />
    <si:transformer ref="bookTransformer" method="transform" />
</si:chain>

<si:recipient-list-router id="purchaseBookRouter" input-channel="purchaseBookRoutingChannel" ignore-send-failures="true" >
        <si:recipient channel="purchaseBookJmsInputChannel" />
        <si:recipient channel="purchaseBookReplyChannel" />
</si:recipient-list-router>

<si-jms:outbound-channel-adapter channel="purchaseBookJmsInputChannel" connection-factory="connectionFactory" destination="bookQueue">
    <si-jms:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">               
            <property name="onFailureExpression" value="#exception" />
            <property name="failureChannel" ref="logginChannel" />
            <property name="trapException" value="true" />
        </bean>
    </si-jms:request-handler-advice-chain>
</si-jms:outbound-channel-adapter>

<si:logging-channel-adapter id="logginChannel" level="WARN"/>

UPDATE

Hi there and thanks for your time!

I think I'm doing something wrong, because I'm testing the request-handler-advice-chain/error-channel and this is what I'm getting:

  • A jms message is sent
  • A JMS error happens (my JMS server is shut down cos I'm testing error handling) and a formatted error log is printed
  • The flow is aborted and no book is purchased

And this is the behaviour that I'm looking for:

  • A jms message is sent
  • A JMS error happens and a formatted error log is printed
  • The book is purchased and the flow ends ok!!

Any clue about how to print the log without aborting the flow?. If I use the property ignore-send-failures="true" the flow ignores the JMS error but no error log is printed.

Have a nice day!

1
I've tested the ExpressionEvaluatingRequestHandlerAdvice & trapException and works perfect! I've updated my attached example with those changes, maybe someone could be keen on this test. Thank you for your support!Miguel N. Olmedo

1 Answers

0
votes

First of all I think you aren't right.

Would be better to publish message to the JMS and only after that return to the reply. So, would be better for real application to change order of channels for the <si:recipient-list-router>.

From other side to log and suppress an exception from the <si-jms:outbound-channel-adapter> you should add <request-handler-advice-chain> to that adapter and provide an ExpressionEvaluatingRequestHandlerAdvice with failureChannel to the <logging-channel-adapter>.

UPDATE

The ExpressionEvaluatingRequestHandlerAdvice has a trapException option. Set it to true and you exception from JMS won't be rethrown.