私はNetflix Feignを使用して、マイクロサービスAの1つの操作をマイクロサービスBの他の操作に呼び出し、Spring Bootを使用してコードを検証しています。
検証がうまくいかなかった場合、マイクロサービス B の操作は例外をスローします。HttpStatus.UNPROCESSABLE_ENTITY
次に、マイクロサービスで処理し、次のように (422)を返します。
@ExceptionHandler({
ValidateException.class
})
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public Object validationException(final HttpServletRequest request, final validateException exception) {
log.error(exception.getMessage(), exception);
error.setErrorMessage(exception.getMessage());
error.setErrorCode(exception.getCode().toString());
return error;
}
したがって、マイクロサービス A が次のようにインターフェイスで B を呼び出すと、次のようになります。
@Headers("Content-Type: " + MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestLine("GET /other")
void otherOperation(@Param("other") String other );
@Headers("Content-Type: " + MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestLine("GET /code/validate")
Boolean validate(@Param("prefix") String prefix);
static PromotionClient connect() {
return Feign.builder()
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.target(PromotionClient.class, Urls.SERVICE_URL.toString());
}
検証に失敗すると、次のメッセージとともに内部エラー 500 が返されます。
{
"timestamp": "2016-08-05T09:17:49.939+0000",
"status": 500,
"error": "Internal Server Error",
"exception": "feign.FeignException",
"message": "status 422 reading Client#validate(String); content:\n{\r\n \"errorCode\" : \"VALIDATION_EXISTS\",\r\n \"errorMessage\" : \"Code already exists.\"\r\n}",
"path": "/code/validate"
}
しかし、マイクロサービス操作 B と同じものを返す必要があります。
Netflix Feign を使用してマイクロサービスを介してステータスと例外を伝達するための最良の方法または手法はどれですか?