Reputation: 5247
I have spring xd module with rabbitmq as a transport. My module has http source http client processor which calls a rest url http://x.y.z/test
stream create --name cycletest4 --definition "http | http-client --url='''https://x.y.z/test''' --httpMethod=GET | log"
http post --data '{ "messageAttribute": { "channelType" : "EML", "contentKey" : "20020", "messageFormat" : "1", "contentSubscriber" : "dmttts", "languageCode" : "en-ca" }, "substitutionKeyValueData" : { "SvcgLOBCd": "CA", "User": "user", "phone": "yyyy, "accountLast": "tttt", "userName": "LP", "Company": "bbbb", "firstName": "Ryan" } }'
Now when my rest client throws any exception like 404 or connection time out exception and the message is going back the rabbit queue between http|http-client
My understanding was only connection time out exception will be put back queue and any other exception or 200 will move the message to next component it is http-client| log.But when i tried it all exception were put back the queue between http|http-client.
Now my usecase was i want to retry all socket time /connection time out exception .any other system exception 50x errors I want to write to log or file sink?How can I achieve this.Basically depending on exception I want to route retry and non retry exception.
Upvotes: 1
Views: 153
Reputation: 61
We tried implementing as suggested above. It is now filtering the 4XX errors and sending the payload to the next module. However the messages are stuck unacknowledged in the internal rabbit mq. The acknowledgement is not happening in case of 2XX also after the change. Before the changes the 2XX acknowledgement was happening fine. The 5XX retry continue to happen just fine. Please let us know how to overcome this.
Here is the context xml
<service-activator input-channel="inputX" ref="gw" />
<gateway id="gw" default-request-channel="toHttp" error-channel="errors" />
<beans:bean id="responseInterceptor" class="com.batch.httpclient.ResponseInterceptor">
</beans:bean>
<chain input-channel="errors" output-channel="output">
<transformer ref="responseInterceptor" />
</chain>
<int-http:outbound-gateway id='batch-http' header-mapper="headerMapper"
request-channel='toHttp' url-expression="${url}" http-method="${httpMethod}"
expected-response-type='java.lang.String' charset='${charset}'
reply-timeout='${replyTimeout}' reply-channel='output'>
</int-http:outbound-gateway>
<beans:bean id="headerMapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper"
factory-method="outboundMapper">
<beans:property name="outboundHeaderNames" value="*"/>
<beans:property name="userDefinedHeaderPrefix" value=""/>
</beans:bean>
<channel id="output" />
<channel id="input" />
<channel id="inputX" />
<channel id="toHttp" />
And the Java code for ResponseInterceptor looks like this -
public Message<String> transform(ErrorMessage errorMessage) {
if(null != errorMessage && null != errorMessage.getPayload() && null != errorMessage.getPayload().getCause()
&& null != errorMessage.getPayload().getCause().getMessage()){
String rootCause = errorMessage.getPayload().getCause().getMessage();
//check if the error message contains 400 or 404 http code.
if(rootCause.contains("400") || rootCause.contains("404")){
return MessageBuilder.withPayload(errorMessage.getPayload().getCause().getMessage())
.copyHeaders(errorMessage.getHeaders())
.removeHeader("errorChannel")
.removeHeader("replyChannel")
.setReplyChannelName("output").setErrorChannelName(null).build();
}
}
return null;
}
}
Upvotes: 0
Reputation: 174719
Only 2xx results will go to the log
.
4xx
and 5xx
are considered errors.
You will need a custom http-client
module to trap the exceptions you consider 'ok' and forward them to the output
channel. Something like...
<int:service-activator input-channel="input" ref="gw" />
<int:gateway request-channel="toHttp" error-channel="errors" />
<int:chain input-channel="errors" output-channel="output">
<!-- examine payload.cause (http status code etc) and decide whether
to throw an exception or return the status code for sending to output -->
</int:chain>
Upvotes: 1