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

JDBC routes repository #43

Open naivefun opened 7 years ago

naivefun commented 7 years ago

Seems there is only memory based implementation now, would be great if it supports persistable repository.

spencergibb commented 7 years ago

Certainly, other implementations will be created. I plan on using spring-data repositories. Since the api is non-blocking, repositories like casandra, redis, mongo and couchbase will fit easier. JDBC will need more work.

naivefun commented 7 years ago

Spring Data JPA is using @Async to offer non-blocking API so maybe that's not a bad idea for now.

spencergibb commented 7 years ago

JDBC is, by definition, blocking. @Async only moves execution to a thread pool.

naivefun commented 7 years ago

Indeed. Is there any other way to enable non-blocking for JDBC?

spencergibb commented 7 years ago

@naivefun nope.

ghoddg commented 6 years ago

whenever we update the routes, we have to restart the gateway server. How can we update the routes dynamically ? is there any way to fetch the routes through jdbc?

samtonyclarke commented 6 years ago

You can publish a new RefreshRoutesEvent() so that its reloaded without a restart.

spencergibb commented 6 years ago

@ghoddg or post to /actuator/gateway/refresh.

ghoddg commented 6 years ago

Thanks Spencer, Do you have the reference implementation project on github with JDBC routes repository?

spencergibb commented 6 years ago

As long as this issue is open, there is not one.

spencergibb commented 6 years ago

@ghoddg not in an unrelated issue. Please ask on stack overflow or gitter.

ghoddg commented 6 years ago

Hello @spencergibb ..can you help me understand on your above comment "or post to /actuator/gateway/refresh"

I have implemented my Config Server with JDBC backend and not GIT. Now, i am thinking how can I use my config server to dynamically update the routes defined in application.yaml

Emmarock commented 6 years ago

@ghoddg do you have any work around yet?

ghoddg commented 6 years ago

Hi @Emmarock we can add the routes in PROPERTIES table of config server and make the gateway as client of config server. Make sure config server should start before the gateway, so when you start gateway, it will load the configuration from config server.

Sample config script for one of service islike below, Insert into PROPERTIES (ID,APPLICATION,PROFILE,LABEL,KEY,VALUE) values (1,'api-gateway','jdbc','jdbc','zuul.routes.api.path','/api/**'); Insert into PROPERTIES (ID,APPLICATION,PROFILE,LABEL,KEY,VALUE) values (2,'api-gateway','jdbc','jdbc','zuul.routes.api.serviceId','ACCOUNT-SERVICE'); Insert into PROPERTIES (ID,APPLICATION,PROFILE,LABEL,KEY,VALUE) values (3,'api-gateway','jdbc','jdbc','zuul.routes.api.stripPrefix','true');

SoftwareKing commented 6 years ago

@spencergibb When does this function be provided?

SoftwareKing commented 6 years ago

@spencergibb ,How to implement dynamic routing? When will this be solved?It's been a long time

spencergibb commented 6 years ago

Nothing has changed.

As long as this issue is open, there is not one.

SoftwareKing commented 6 years ago

Which spring cloud gateway version is planned to support? @spencergibb

spencergibb commented 6 years ago

It is not planned

spencergibb commented 6 years ago

And probably won't be until there is a reactive jdbc solution for spring.

kvneswar commented 6 years ago

I'm new to Spring cloud gateway and reactivate programming. As per my understanding, routes will get loaded into heap during the server startup or whatever we call refresh API(actuator). Blocking vs Non blocking JDBC driver(reactivate), does it have huge impact on performance if we use regular JDBC driver or am I missing something? @spencergibb

dominik-kovacs commented 8 months ago

what about spring data r2dbc?

spencergibb commented 8 months ago

yup, r2dbc would be what we use for reactive gateway server

sarbesh commented 4 months ago

Hi, Am not sure if this is relevant to the discussion above, but am using JDBC backend to store my Spring Gateway routes and have defined as in the screenshot attached

Screenshot 2024-07-17 at 00 11 03

I added routes to my MySQL table and called the [POST] Gateway-Service/actuator/refresh API to refresh the config, and the new routes were added automatically during runtime without the need for a Gateway-service restart