I think I see where you're coming from. Can we assume my paradigm is 
slightly different and I have a set of servers servicing streaming requests 
and I want to establish session affinity to those servers when a request is 
made to connect. Is this possible? 

In my current implementation the server handling the request is loading all 
of the necessary data into memory and I'd like to have that same server 
handle requests on subsequent calls.

On Wednesday, May 6, 2020 at 3:16:19 PM UTC-4, Christian Rivasseau wrote:
>
> 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 <[email protected] <javascript:>> 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 [email protected] <javascript:>.
>> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/489e5e3e-aa03-471e-bd20-67add01e8d85%40googlegroups.com.

Reply via email to