LogNet / grpc-spring-boot-starter

Spring Boot starter module for gRPC framework.
Apache License 2.0
2.23k stars 433 forks source link

Override default port 6565 #201

Closed bhardwahnitish19 closed 3 years ago

bhardwahnitish19 commented 3 years ago

I am facing hard time overriding default port of grpc:6565. Strange thing is that the services starts twice, once over default port and then on port -1.

2021-04-22 18:54:50.187  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : Starting gRPC Server ...
2021-04-22 18:54:50.274  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'com.jio.distc.grpc.service.HelloService' service has been registered.
2021-04-22 18:54:50.296  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'io.grpc.protobuf.services.ProtoReflectionService' service has been registered.
2021-04-22 18:54:50.680  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : gRPC Server started, listening on port 6565.
2021-04-22 18:54:50.682  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : Starting gRPC Server ...
2021-04-22 18:54:50.689  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'com.jio.distc.grpc.service.HelloService' service has been registered.
2021-04-22 18:54:50.691  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'io.grpc.protobuf.services.ProtoReflectionService' service has been registered.
2021-04-22 18:54:50.698  INFO 7756 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : gRPC Server started, listening on port -1.
2021-04-22 18:54:50.722  INFO 7756 --- [           main] com.jio.distc.DistcNodeApplication       : Started NodeApplication in 6.452 seconds (JVM running for 9.342)

application.yaml

grpc:
  port: ${SERVER_PORT:7575} //This is completely ignored at runtime
  enableReflection: true
  inProcessServerName: ${SERVER_NAME:Node1}
  netty-server:
    keep-alive-time: ${NETTY_KEEP_ALIVE_TIME:30s}
    max-inbound-message-size: ${NETTY_MAX_INBOUND_MESSAGE_SIZE:500MB}
    primary-listen-address: ${NETTY_LISTEN_ADDRESS:127.0.0.1}

Moreover, grpc service is not accessible as a docker container.

Dockerfile

FROM openjdk:15-alpine
ARG JAR_FILE=build/libs/*-node.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

docker-compose.yaml


#
# Copyright GRPC-Node
#
#
version: '2'

networks:
  basic:
    external:
      name: cluster

services:
  distc-node:
    container_name: node1
    image: xxxx-node
    environment:
      - SERVER_PORT=7575
      - SERVER_NAME=node1
      - NETTY_KEEP_ALIVE_TIME=30s
      - NETTY_MAX_INBOUND_MESSAGE_SIZE=500MB
      - NETTY_LISTEN_ADDRESS=127.0.0.1
      - TIMER=5
    ports:
      - "8121:6565"
CONTAINER ID        IMAGE             COMMAND              CREATED                STATUS                 PORTS                               NAMES
aa53ac834746        distc-node      "java -jar /app.jar"     47 seconds ago      Up 46 seconds      0.0.0.0:8121->6565/tcp     node1                                                                                                           

Logs from docker container:

distc-node1   | 2021-04-22 13:19:40.979  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : Starting gRPC Server ...
distc-node1   | 2021-04-22 13:19:41.039  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'com.jio.distc.grpc.service.HelloService' service has been registered.
distc-node1   | 2021-04-22 13:19:41.190  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : gRPC Server started, listening on port 6565.
distc-node1   | 2021-04-22 13:19:41.192  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : Starting gRPC Server ...
distc-node1   | 2021-04-22 13:19:41.200  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'com.jio.distc.grpc.service.HelloService' service has been registered.
distc-node1   | 2021-04-22 13:19:41.209  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : gRPC Server started, listening on port -1.
distc-node1   | 2021-04-22 13:19:41.242  INFO 1 --- [           main] com.jio.distc.DistcNodeApplication       : Started DistcNodeApplication in 4.17 seconds (JVM running for 5.098)

But, the service doesn't work either on 8121 or 7575 or 6565

On 8121, an error returned:

{
  "error": "2 UNKNOWN: Stream removed"
}

On 6565 and 7575:

{
  "error": "14 UNAVAILABLE: failed to connect to all addresses"
}
jvmlet commented 3 years ago

How did you build the image with grpc server? Regarding server started twice - because you enabled inpoc server, -1 is its port

bhardwahnitish19 commented 3 years ago

I created a jar using gradle and ran docker build . -t xxxx-node

jvmlet commented 3 years ago

Can you share your. dockerfile? You are running image: node in your compose file... right?

bhardwahnitish19 commented 3 years ago

yes, updated the question with Dockerfile. Actually, it'simage: xxxx-node, the same name that is being used in the image tag.

jvmlet commented 3 years ago

Can you try to pass environment variable GRPC_PORT=7575 in docker compose and bind 8121 to 7575?

bhardwahnitish19 commented 3 years ago

Just tried it, but it's ignored too as it's being ignored in local IDE. The server started on 6565.

distc-node1   | 2021-04-22 15:32:07.211  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : gRPC Server started, listening on port 6565.
distc-node1   | 2021-04-22 15:32:07.213  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : Starting gRPC Server ...

docker-compose.yaml

version: '2'

networks:
  basic:
    external:
      name: cluster

services:
  distc-node:
    container_name: distc-node1
    image: distc-node
    environment:
      - GRPC_PORT=7575
      - SERVER_NAME=Distc-node1
      - NETTY_KEEP_ALIVE_TIME=30s
      - NETTY_MAX_INBOUND_MESSAGE_SIZE=500MB
      - NETTY_LISTEN_ADDRESS=:6565
      - GOSSIP_ROUNDS=2
      - GOSSIP_FANOUT=2
      - GOSSIP_CLIENT_ID=127.0.0.1:7575
      - TIMER=5
    ports:
      - "8121:7575"
      - "8122:6767"

image

jvmlet commented 3 years ago

Can you show the IDE settings how you run your app? Can try also with --grpc.port=7575 argument from IDE?

bhardwahnitish19 commented 3 years ago

I changed NETTY_LISTEN_ADDRESS=:6565 to NETTY_LISTEN_ADDRESS=:7575 and kept everything as is in docker-compose.yaml, I can see the log that this time server has started on 7575

distc-node1   | 2021-04-22 16:03:20.673  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'com.jio.distc.grpc.service.HelloService' service has been registered.
distc-node1   | 2021-04-22 16:03:20.688  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : 'io.grpc.protobuf.services.ProtoReflectionService' service has been registered.
distc-node1   | 2021-04-22 16:03:20.833  INFO 1 --- [           main] o.l.springboot.grpc.GRpcServerRunner     : gRPC Server started, listening on port 7575.

But, still getting the same error from GRPC client

image

bhardwahnitish19 commented 3 years ago

I am using the same setting/config in application.yaml. When I use NETTY_LISTEN_ADDRESS=:7575 server in IDE starts at 7575.

I am able to access API using localhost 127.0.0.1 when the server is running in IDE. But, it's unreachable as docker container.

image

jvmlet commented 3 years ago

Don't you need to expose port in docker file?

jvmlet commented 3 years ago

Also, I haven't seen double quotes being used when binding ports in compose file

bhardwahnitish19 commented 3 years ago

Yeah, but even that doesn't help. Exposed port 7575 in docker file and server started on 7575 as a docker container. But, still getting the same error.

{
  "error": "2 UNKNOWN: Stream removed"
}
bhardwahnitish19 commented 3 years ago

I guess we can use double quotes in docker-compose to bind ports.

Please check this same: https://github.com/hyperledger/fabric-samples/blob/main/test-network/docker/docker-compose-couch.yaml

jvmlet commented 3 years ago

Try to remove primary-listen-address from application yaml

bhardwahnitish19 commented 3 years ago

Thanks, it works on removing primary-listen-address from application yaml. Server started on port 7575 and able to connect to docker container from bloomrpc.

Thanks a lot for your support and patience. :)

jvmlet commented 3 years ago

Yes, primarily listen address takes precedence over grpc.port property and is expected to be in host:port format. Missed that....

bhardwahnitish19 commented 3 years ago

makes sense. Thanks @jvmlet really appreciate your support.