I am trying to build an ldempotentInterceptors, I want to save a token in the header, save the token and response in the first gRPC call, and query the response through the token in the second call, and return directly.
My searches have come across:
https://github.com/grpc/grpc-java/issues/1712
https://engineering.kabu.com/entry/2021/03/31/162401
https://groups.google.com/g/grpc-io/c/_osH2D6L9Ck/m/FdvqQgkRDgAJ
I don't know what to do, hope can get help
Am I missing something obvious?
PS. A big thank you to all the maintainers
public class IdempotentInterceptors implements ServerInterceptor {
private static final Metadata.Key<String> CLIENT_HEADER_KEY = Metadata.Key.of("token", Metadata.ASCII_STRING_MARSHALLER);
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
String token = headers.get(CLIENT_HEADER_KEY);
MethodDescriptor<ReqT, RespT> methodDescriptor = call.getMethodDescriptor();
String serviceName = methodDescriptor.getServiceName();
String bareMethodName = methodDescriptor.getBareMethodName();
log.info("1、header received from client token: {}, serviceName: {}, bareMethodName: {}", token, serviceName, bareMethodName);
ServerCall<ReqT, RespT> wrapperCall =
new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void sendMessage(RespT response)
save(token, response);
super.sendMessage(response);
}
};
ServerCall.Listener<ReqT> listener = next.startCall(wrapperCall, headers);
return new ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(listener) {
@Override
public void onMessage(ReqT request) {
RespT response = null;
if (token != null) {
response = (RespT) select(token);
}
if (response != null) {
//
} else {
super.onMessage(request);
}
}
};
}
}
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/878a29fd-71c3-4356-a69a-3a87d6864be6n%40googlegroups.com.
java.lang.IllegalStateException: java.lang.IllegalStateException: call already closed
...
Caused by: java.lang.IllegalStateException: call already closed
I have a new discovery, which may occur in serialization and deserialization, and an exception occurs, causing the problem to report an error ”call already closed“
CREATE TABLE `idempotent_request` (
`id` bigint(19) NOT NULL AUTO_INCREMENT COMMENT '主键',
`prj_name` varchar(64) DEFAULT NULL COMMENT '项目名称',
`interface_name` varchar(64) DEFAULT NULL COMMENT '服务名称',
`request_id` varchar(256) DEFAULT NULL COMMENT '请求id',
`response` blob COMMENT '响应',
`biz_column_values` varchar(512) DEFAULT NULL COMMENT '冗余业务字段',
`sign` varchar(64) DEFAULT NULL COMMENT '摘要签名',
`status` tinyint(1) DEFAULT NULL COMMENT '状态',
`valid_end_time` datetime DEFAULT NULL COMMENT '有效期',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8mb4;
When I was debugging, I found that it should be caused by the inability to serialize the response, but I don't know how to improve it. I look forward to your reply.
at com.alibaba.csp.sentinel.adapter.grpc.SentinelGrpcServerInterceptor$1.close(SentinelGrpcServerInterceptor.java:77) ~[sentinel-grpc-adapter-1.7.1.jar:?]
at com.opay.ccp.proxy.interceptor.IdempotentInterceptors.interceptCall(IdempotentInterceptors.java:71) ~[classes/:?]
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/d81415b0-1228-4186-b165-cff52d7fc43fn%40googlegroups.com.