Hello,
I would like to cache a GRPC stub into redis. Is this possible? When I try I get serialzation errors. I've tried adding serialization methods onto the generated stub classes but still get serialization errors. I am using java but open to using other implementations.
Thanks in advance for the insight!
Here is my serialization code.
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9002)
.usePlaintext()
.build();
MyGrpc.MyStub myStub = MyGrpc.newStub(channel);
StreamObserver<MessageResponse> responseObserver = new ServerCallStreamObserver<MessageResponse>() {
...
};
myStub.doubleStream(responseObserver);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(myStub);
out.flush();
byte[] value = bos.toByteArray();
bos.close();
Jedis jedis = new Jedis("localhost", 6379);
byte[] key = "key".getBytes();
jedis.setex(key, 10, value);
byte[] bytes = jedis.get(key);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInput in = new ObjectInputStream(bis);
MyGrpc.myStub cachedStub = (MyGrpc.MyStub) in.readObject();
When I try to deserialize the object I get the following error.
Exception in thread "main" java.io.NotSerializableException: ai.com.proxy.generated.MyGrpc$MyStub
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at ai.com.proxy.ProxyApplication.main(ProxyApplication.java:83)