Home > Back-end >  WebFlux reactive programming, through the redis test appkey problem, urgent request
WebFlux reactive programming, through the redis test appkey problem, urgent request

Time:05-27

If abnormal redis connection, will the ex processing, but redis is normal, but not for processing, directly into the chain. In the filter (exchange), how to do


 @ Resource 
Private AppKeyProvider AppKeyProvider;

Public Mono The filter (ServerWebExchange exchange, GatewayFilterChain chain) {
Try {
String app_key=exchange. GetRequest (). GetQueryParams (). The getFirst (" app_key "));
//app_key verify
Flux. Just (app_key). FlatMap (key - & gt; AppKeyProvider. GetAppKey (key)). The subscribe (
AppKey - & gt; {
If (appKey==null) {
//app_key is not valid
Throw new AppException (ErrorCode. ILLEGAL_APP_KEY);
} else {
//do... Jump to the next filter
}
},
The ex - & gt; {
Throw new AppException (ErrorCode SERVICE_BASIC_ERROR, ex);
}
);
{} the catch (AppException ex)
Exchange. The method getResponse (). SetStatusCode (HttpStatus BAD_REQUEST);
Exchange. The method getResponse (). GetHeaders () setContentType (MediaType. APPLICATION_JSON);
The String result=RestHelper. Build (ex, exchange). The toString ();
Return exchange. The method getResponse (). WriteWith (Mono) just (exchange. The method getResponse () bufferFactory (). Wrap (result. GetBytes (Charsets. UTF_8))));
}
return chain.filter(exchange);
}

CodePudding user response:

There is no reply, top a himself
  • Related