spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.55k stars 3.33k forks source link

Unable to integrate grpc with spring cloud gateway #3388

Closed ShivaniSK closed 6 months ago

ShivaniSK commented 6 months ago

I am trying to integrate grpc with spring cloud gateway. I want to hit a grpc url and redirect it to the grpc service. My gateway config looks like below

...
..
..
server:
  port: 8080
  http2:
    enabled: true
spring:
  application:
    name: API Gateway
  main:
    banner-mode: "off"
    web-environment: false
    web-application-type: reactive
    allow-bean-definition-overriding: true
    allow-circular-references: true
  cloud:
      gateway:
          filter:
            remove-hop-by-hop:
              headers:
                - connection
                - keep-alive
                - transfer-encoding
                - proxy-authenticate
                - proxy-authorization
                - x-application-context
                - upgrade
          httpclient:
            wiretrap: true
            ssl:
              use-insecure-trust-manager: true
          httpserver:
            wiretrap: true
          routes:
            - id: grpc-test
              uri: ${service_grpc_url:grpc://grpc-test:50053}
              predicates:
              - Path= /grpc-api/**
              filters:
              - RewritePath=/grpc-api(?<segment>/?.*), $\{segment}
       ..
..
..

On deploying above changes, when i hit the below gateway url grpc://<api-gateway-host>:8080/grpc-api It does not redirect to grpc://grpc-test:50053 . I get "service unavailable error". I am able to reach the grpc service pod directly by hitting grpc://grpc-test:50053, but its not redirecting via api-gateway. I am using springboot version 3.2.3. Spring cloud version is 2023.0.0. I have added below dependencies

implementation (group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client')
   implementation (group: 'org.springframework.boot', name: 'spring-boot-starter-security')
   implementation (group: 'org.springframework.boot', name: 'spring-boot-starter-web')
   implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
   implementation group: 'org.springframework.cloud', name: 'spring-cloud-openfeign-core'

Can you please help me out on the issue. Or let me know if have missed out on anything. Do i need to add any grpc specfic dependency?

jivebreaddev commented 6 months ago

`Please try Spring Bean Configuration method to configure gateway for a fix for now.

yaml configuration to build a gateway seems to have an issue when binding the values.`

Sorry for the confusion I have made. I am working on the debugging to find the solution for it

Please ignore the answer I have given you. Will get back to you once I found the reasons.

ShivaniSK commented 6 months ago

Hi @jivebreaddev , Sure thanks. Kindly let me know if its working fine for you or if anything missed from my side.

ShivaniSK commented 6 months ago

Hi @jivebreaddev , is there any update ?

ShivaniSK commented 6 months ago

Closing the ticket as raised another one with exact issue https://github.com/spring-cloud/spring-cloud-gateway/issues/3411