forget99 opened a new issue, #247:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/247
### Issue description
在路由上配置了一个前置插件ext-plugin-pre-req和后置插件ext-plugin-post-resp,在前置插件中获取请求信息,在后置插件中获取响应信息,在多线程环境下,如何将请求数据串联起来。使用线程id和requestId都会出现错乱。
### code
@Override
public void filter(HttpRequest request, HttpResponse response,
PluginFilterChain chain) {
long requestId = request.getRequestId();
String uuid = UuidUtil.create2();
Thread thread = Thread.currentThread();
thread.setName(uuid);
logger.info("【前置拦截过滤器线程名称】:" + uuid);
String path = request.getPath();
requestPathMaps.put(uuid, path);
chain.filter(request, response);
}
@Override
public void postFilter(PostRequest request, PostResponse response,
PluginFilterChain chain) {
Thread thread = Thread.currentThread();
String uuid = thread.getName();
logger.info("【后置拦截过滤器线程名称】:" + uuid);
long requestId = request.getRequestId() - 1;
String responseBody = formatBody(request.getBody());
logger.info("【后置拦截过滤器接口路径】:" + requestPathMaps.get(uuid));
logger.info("【后置拦截过滤器接口响应结果】:" + responseBody);
response.setBody(responseBody);
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]