'grpc client docker-compose to listen a port from grpc server
2 file GRPC Client and GRPC Server if i run it manual to my IDE its able to connect to the localhost:9090 and send data while the GRPC Server is running in Docker.
But if i used docker-compose.yaml in GRPC CLIENT it wont listen to 9090.
2 file GRPC Client and GRPC Server if i run it manual to my IDE its able to connect to the localhost:9090 and send data while the GRPC Server is running in Docker.
But if i used docker-compose.yaml in GRPC CLIENT it wont listen to 9090.
//Client Service
@Service
public class ProductService {
private ManagedChannel channel;
private ProductServiceGrpc.ProductServiceStub productServiceStub;
private ProductServiceGrpc.ProductServiceBlockingStub productServiceBlockingStub;
private void initializeStub() {
channel = ManagedChannelBuilder.forAddress("localhost", 9090).usePlaintext().build();
productServiceBlockingStub = ProductServiceGrpc.newBlockingStub(channel);
productServiceStub = ProductServiceGrpc.newStub(channel);
}
public ProductService() {
initializeStub();
}
}
//Client side
//application.yaml
server:
port: ${SERVER_PORT:8094}
grpc:
server:
port: ${GRPC-SERVER-PORT:9099}
//GRPC Client
//Docker-compose.yaml
version: '3.8'
networks:
default:
name: product-poc-project-net
external: true
services:
cartgatewayservice:
image: cartgatewayservice:latest
container_name: cartgatewayservice
restart: unless-stopped
build:
context: ./
dockerfile: Dockerfile
ports:
- 9000:8094
environment:
SERVER_PORT: 8094
GRPC-SERVER-PORT: 9090
GRPC-SERVER_HOST: cartservice
//GRPC Service
//Docker-compose.yaml
version: '3.8'
networks:
default:
name: product-poc-project-net
external: true
services:
cartservice:
image: cartservice:latest
container_name: cartservice
depends_on:
- cart-mysqldb
restart: always
build:
context: ./
dockerfile: Dockerfile
ports:
- "9090:9090"
environment:
MYSQL_HOST: cart-mysqldb
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_PORT: 3306
GRPC-SERVER-PORT: 9090
cart-mysqldb:
image: mysql:8.0.28
restart: unless-stopped
container_name: cart-mysqldb
ports:
- "3307:3306"
cap_add:
- SYS_NICE
environment:
MYSQL_DATABASE: dbpoc
MYSQL_ROOT_PASSWORD: root
Solution 1:[1]
i just fix it refrence link Cannot connect to my containerized gRPC server
solution: change localhost to container_name that you try to connect
channel= ManagedChannelBuilder.forAddress("cartservice",9090).usePlaintext().build();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ConRed |
