It seems to me that it is possible to run gRPC server on Servlet Server 
sharing the same port, say 8080 (see Servlet Server section of Spring gRPC 
doc https://docs.spring.io/spring-grpc/reference/server.html). Below is 
part of my pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath />  <!--lookup parent from repository -->
</parent>

<properties>
<java.version>17</java.version>
<grpc.version>1.70.0</grpc.version>
<protobuf-java.version>3.25.6</protobuf-java.version>
<spring-grpc.version>0.7.0</spring-grpc.version>
</properties>

<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc-server-web-spring-boot-starter</artifactId>
</dependency>
... ... ...

Following is the console log when the app starts

toConfiguration$GrpcServletConfiguration : Registering gRPC service: 
StatusQuery
toConfiguration$GrpcServletConfiguration : Registering gRPC service: 
grpc.reflection.v1.ServerReflection
toConfiguration$GrpcServletConfiguration : Registering gRPC service: 
grpc.health.v1.Health

... ... ...

o.s.b.d.a.OptionalLiveReloadServer             : LiveReload server is 
running on port 35729
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 
(http) with context path '/web-context'
                                          : Started QueryServiceApplication 
in 23.59 seconds (process running for 25.383)
o.a.c.c.C.[.[.[/web-context]                           : Initializing 
Spring DispatcherServlet 'dispatcherServlet'
o.s.web.servlet.DispatcherServlet                       : Initializing 
Servlet 'dispatcherServlet'
o.s.web.servlet.DispatcherServlet                        : Completed 
initialization in 3 ms

Then try to call grpc service by using grpcurl but get error

grpcurl -d "{\"name\":\"USA\"}" -plaintext localhost:8080 
HelloWorld.SayHello
Error invoking method "HelloWorld.SayHello": failed to query for service 
descriptor "HelloWorld": server does not support the reflection API

grpcurl -d "{\"name\":\"USA\"}" -plaintext localhost:8080 
HelloWorld/SayHello
Error invoking method "HelloWorld/SayHello": failed to query for service 
descriptor "HelloWorld": server does not support the reflection API

grpcurl -d "{\"name\":\"USA\"}" -plaintext localhost:8080 
web-context/HelloWorld/SayHello
Error invoking method "web-context/HelloWorld/SayHello": failed to query 
for service descriptor "web-context/HelloWorld": server does not support 
the reflection API

Does anyone have some idea?

On Tuesday, November 28, 2017 at 8:05:57 PM UTC-5 spenc...@google.com wrote:

> Hi Linesh,
> gRPC expects full control over the listening socket in the case of server 
> side, and expects full control over creating and tearing down connections 
> in the case of client side. This doesn't really fit into the model of a 
> servlet container, which is what Tomcat is. If you really must create a 
> gRPC server on the same JVM as Tomcat, you can add the normal gRPC startup 
> code to whatever server start up code you already have:
>
> https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java#L36
>
> Keep in mind that gRPC is not a servlet container, so it will not be able 
> to run your existing Tomcat servlets.
>
>
> On Monday, November 27, 2017 at 1:24:27 AM UTC-8, Linesh Mohan wrote:
>>
>> Hello Team,
>>
>> I am trying to start to gRPC server within a tomcat deployment and facing 
>> some issues. I am trying the achieve the following -
>> I have an app server deployed on tomcat and now I want to use gRPC, hence 
>> I want to deploy a gRPC server on the same app server.
>>
>> Kindly help me with the above case.
>>
>> Thanks in advance.
>> Linesh
>>
>

-- 
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 visit 
https://groups.google.com/d/msgid/grpc-io/454c988e-654c-4402-938a-dfb72bd726bbn%40googlegroups.com.

Reply via email to