Announcement Announcement Module
No announcement yet.
Customer error channel for JMS outbound channel adapter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Customer error channel for JMS outbound channel adapter


    Is there a way to configure a customer error channel for a JMS outbound channel adapter?

    If for whatever reason the connection to the messaging broker (in this case Hornet Q) goes down I want to be able to log the message payload so it is not lost.

    I have a service activator configured for the default 'errorChannel' & can see how to extract the failed message from the MessageHandlingException but I only want to log this in the event of a JmsException. Instead of doing a check on the actual exception type I wondered if I could just setup a new custom error channel.

    Many Thanks.

  • #2
    Error channels are not defined on outbound endpoints.

    You can, however, add an ExpressionEvaluatingAdvice to the adapter with the 'onFailureExpression' be and wire the failureChannel to a logging-channel-adapter.


    • #3
      Hi Gary ,

      Thanks for that. I went over the documentation on adding behaviour to endpoints & the RequestHandlerRetryAdvice suited my requirement better as I can include the retry configuration as well as a recoveryCallback property where I write the message to a log.

      The functionality I am working on receives a HTTP request on an inbound-gateway, does some conversion and puts the message onto a JMS queue. An additional requirement I have been given is to return a HTTP 200 response in the event that the message is successfully added to the queue. If adding the message to the queue fails a 500 status code should be returned.

      Is it possible to update the response code of the inbound-gateway based on the result of the jms:outbound-channel-adapter? I tried to implement a ExpressionEvaluatingRequestHandlerAdvice but onFailure was getting called every time a retry attempt failed. I also tried to do add it in the recoveryCallback but the status value was being returned. Would you be able to give me some pointers on how I might do this?

      The code I currently have is as follows:

      	<bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>
      	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
      	<int:channel id="httpRequestChannel" />	
      	<int:channel id="httpResponseChannel" />
      	<!-- Subscriber to cnpshHttpInboundGateway -->
              <int:chain id="callbackChain" 
               	<int:filter expression="payload != null 
          				and payload.getClass().getName().equals('org.springframework.util.LinkedMultiValueMap')	
          				and !payload.isEmpty()"/>
              	<int:transformer method="transform" ref="messageToMapTransformer"/>
          	        <!-- Remove all HTTP header values -->
               	<int:header-filter header-names="*"/>
      	<int:channel id="jmsInputChannel" />
      	<!-- JMS Producer -->
      	<int-jms:outbound-channel-adapter auto-startup="true" id="jmsOutAdapter" channel="jmsInputChannel" destination-name="CallbackQueue">
      	        <bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
      	            <property name="recoveryCallback">
      	                <bean class="org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer">
      	                    <constructor-arg ref="outboundErrorChannel" />
      	            <property name="retryTemplate" ref="retryTemplate" />
      	<bean id="retryTemplate" class="">
      		<property name="retryPolicy">
      			<bean class="org.springframework.retry.policy.SimpleRetryPolicy">
      				<property name="maxAttempts" value="2" />
      		<property name="backOffPolicy">
      			<bean class="org.springframework.retry.backoff.FixedBackOffPolicy">
      				<property name="backOffPeriod" value="1000" />
       	<int:channel id="outboundErrorChannel"/>
      	<int:service-activator input-channel="outboundErrorChannel" ref="outboundErrorLogger" method="logOutboundError"/>
      	<int:channel id="callbacksErrorChannel"/>
      	<int:chain input-channel="callbacksErrorChannel">
      		<int:transformer ref="errorUnwrapper" />
      		<int:service-activator ref="errorLogger" method="logError"/>

      Many thanks.


      • #4
        If you throw an exception in the recovery callback (or whatever is downstream of 'outboundErrorChannel') you should get a 500 status code returned to the caller.

        When chaining advices together, the order is important (e.g. an expression evaluating advice after a retry advice will be called for each retry; if it's before the retry advice, it will be called once after the retries are exhausted.