How to close a server side stream from an android client without shutdown the channel.

39 views
Skip to first unread message

Daniele Soprani

unread,
Aug 23, 2024, 2:23:50 PMAug 23
to grpc.io
Hi, I'm building an android application that open a server side streaming communication. I want to programmatically close it leaving the channel active. 

val stub = ControlsGrpc.newStub(getChannel()).withInterceptors(
         MetadataUtils.newAttachHeadersInterceptor(getAuthInterceptor())
      )
     
stub.subscribeToDeviceEvents(Empty.newBuilder().build(), observer)

The subscribeToDeviceEvents function returns Unit value, I only have the observer.
Thanks a lot 

Larry Safran

unread,
Aug 23, 2024, 4:05:03 PMAug 23
to Daniele Soprani, grpc.io
Hi Daniele,
  What are you trying to accomplish with the close?

-- Larry

--
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/a4c4ad9e-bda5-405f-aa7b-1908f2087c43n%40googlegroups.com.

Daniele Soprani

unread,
Aug 28, 2024, 1:33:00 PMAug 28
to grpc.io
I'm trying to cancel the grpc stream and release the resources. I already found a solution for my problem. I post here so anyone can use it:

      val stub = ControlsGrpc.newStub(getChannel()).withInterceptors(
         MetadataUtils.newAttachHeadersInterceptor(getAuthInterceptor()),
      )
     
      val withCancellation: CancellableContext = Context.current().withCancellation()
      withCancellation.run {
         stub.subscribeToDeviceEvents(Empty.newBuilder().build(), observer)
      }
     
      return withCancellation

Reply all
Reply to author
Forward
0 new messages