Search code examples
spring-integrationamqpspring-amqp

Spring integration handler error in outbound-channel-adapter --> confirm-ack-channel


I want to do:

  1. Receive message from web service
  2. Send xml message to rabbit
  3. Validate xml to xsd --> Launch exception (validation incorrect)
  4. Return custom error message to web service

Step 1: Receive message from web service --> RESULT OK

<ws:inbound-gateway id="ws-inbound-gateway"
        request-channel="requestChannel" reply-channel="replyChannel" reply-timeout="300000"
        error-channel="errorChannel" />
<int:chain input-channel="requestChannel" output-channel="inbound">
        <int:service-activator ref="defaultLogger" method="logger"/>
</int:chain>

Step 2: Write a xml message in fanout exchange rabbit --> RESULT OK

<int-amqp:outbound-channel-adapter 
    channel="inbound" amqp-template="amqpTemplate" return-channel="outbound"
    exchange-name="es.queue.test"
    confirm-ack-channel="confirmAck" confirm-nack-channel="confirmNack" confirm-correlation-expression="#this" />

Step 3: Validate xml to xsd --> Result ok XsdValidationException

<int:chain input-channel="confirmAck" output-channel="outbound">
        <int:service-activator ref="defaultLogger" method="logger"/>
        <int-xml:validating-filter schema-type="xml-schema"
            schema-location="classpath:/schema/prueba.xsd"
            throw-exception-on-rejection="true" discard-channel="errorChannel" />
    </int:chain>

In this step the message will be sent to errorChannel but I have the next error:

 63863 [AMQP Connection 10.0.9.155:5672] ERROR o.s.a.r.s.PublisherCallbackChannelImpl - Exception delivering confirm 
org.springframework.integration.MessageRejectedException: Message was rejected due to XML Validation errors; nested exception is org.springframework.integration.xml.AggregatedXmlMessageValidationException: Multiple causes:
    cvc-elt.1: No se ha encontrado la declaración del elemento 'ns2:***'.

    at org.springframework.integration.xml.selector.XmlValidatingMessageSelector.accept(XmlValidatingMessageSelector.java:134)
    at org.springframework.integration.filter.MessageFilter.doHandleRequestMessage(MessageFilter.java:161)
    at org.springframework.integration.handler.AbstractReplyProducingPostProcessingMessageHandler.handleRequestMessage(AbstractReplyProducingPostProcessingMessageHandler.java:46)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)

Step 4: The web service client never receive response I think that it's error "Exception delivering confirm" occurs because the exception is throw in thread AMQP when try send confirm ack.

Can you help me?


Solution

  • Everything looks good unless you should explain to us why do you use throw-exception-on-rejection="true" and break your flow?

    I even think that confirm-correlation-expression="#this" really passes a requestMessage to the confirm-ack-channel, so you can send reply back to the WS Gateway from that sub-flow.

    But! Since you throw-exception-on-rejection="true" nothing is going to be sent to the outbound channel.

    Also return-channel is not for reply. It is another error state, when Broker can't deliver the message to the queue because of some misconfiguration there: http://www.rabbitmq.com/blog/2011/02/10/introducing-publisher-confirms/