It doesnt really make sense to cache a stub in redis, just like it wouldn't
make sense to serialize a socket,
or a thread pool. Those kind of objects only have an use in a given process.

On Wed, May 6, 2020 at 9:06 PM <georgepfos...@gmail.com> wrote:

> 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)
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grpc-io/26c472dd-8066-4477-9166-7c1e3fccb6f0%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/26c472dd-8066-4477-9166-7c1e3fccb6f0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Christian Rivasseau
Co-founder and CTO @ Lefty <http://www.lefty.io>
+33 6 67 35 26 74

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAJ6g4%3DbrW%3D6RfhQdZLdnwL5F8sJQLWAerT91gAF1ho8XcjQm_g%40mail.gmail.com.

Reply via email to