Dynamic Service Registration server side in Java

554 views
Skip to first unread message

quackerjeff

unread,
Oct 3, 2016, 8:33:42 PM10/3/16
to grpc.io
I read a previous posting that it's possible to register multiple services in one server dynamically.  I'm using a MutableHandlerRegistry but it's addService takes a serviceName or a ServerServiceDefinition.  The ServiceBuilder.addService takes a BindableService.  What do I need to do?  I'm at a complete and utter loss.  I was hoping to have one server listening on one port
to handle my services.  Are there any examples?  How does the serviceName relate to my service implementation,etc?

Thank you!

Louis Ryan

unread,
Oct 3, 2016, 8:39:08 PM10/3/16
to quackerjeff, grpc.io
ServerBuilder...
   .addService(new ServiceImplOne())
   .addService(new ServiceImplTwo())
   .build()l

where ServiceImplOne is a concrete subclass of a generated stubs XXXImplBase class (look for an abstract class in the generated code which implements BindableService)

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/54c47570-ed79-4edf-b368-b34e94f21d0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Andrews

unread,
Oct 3, 2016, 8:42:55 PM10/3/16
to Louis Ryan, grpc.io
Louis,

Thanks for the quick response.  I get what you did, but that’s more static, I meant at runtime.  

In other words, after my Server is built and running, I want to be able to add or remove services on the fly.

Jeff

Louis Ryan

unread,
Oct 3, 2016, 8:48:41 PM10/3/16
to Jeffrey Andrews, grpc.io
Ahh ok. then you want something like

MutableHandlerRegistry registry = new MutableHandlerRegistry();
ServerBuilder....
   fallbackHandlerRegistry(registry)
   .build();

Some time later...

ServiceImplOne serviceInstance = new ServiceImplOne(...);
registry.addService(serviceInstance.bindService());

... and to remove ....

registry.removeService(serviceInstance.bindService());


Note that this is using APIs marked as @Experimental and therefore not subject to our API stability guarantees

Reply all
Reply to author
Forward
0 new messages