Spring Cloud Gateway - Refreshing routes - spring-cloud

Using spring-cloud-gateway 2.0.0.M5, Im defining routes in configuration file (application.yml). I'm trying to update these routes by calling POST /application/gateway/refresh.
Modified routes, or new routes, are not refreshed, even though I see (with a breakpoint) that a refresh routine is actually executed.
Is the refresh supposed to work when routes are defined in configuration files ? Something I am missing ?
The use case would be routes defined in spring config server.

For those struggling with the same issue, here is a setup which works with 2.0.0.M5:
Routes configuration in application.yml file hosted in Spring Cloud Config Server (2.0.0.M7)
Add/Delete/Modify routes in application.yml
POST /actuator/refresh --> this will reload the routes definitions
POST /application/gateway/refresh --> this will reload the routes
Try new routes

Related

React project running on same server as node client routing

My project directory structure is implement in a way that the frontend dir sits inside the main dir where index.js of server file lives.
The problem is when I try to route to a specific page on client /about for example.
The call will be made to the server and not to client. on the home page / the server sends the call to /frontend/build/index.js. How can I achieve the same result to other routes?
Problem was routes order on the index.js file of server

Spring Web: Mapping URL to a standalone Spring app

I have two standalone Spring Boot/Web web app .jars, A and B, both made by third-parties, with their own URL mappings which I do not know about in advance.
I would like to create a setup where "localhost:8080/A" maps (passes through) to A's "/" mapping. Similarly, "localhost:8080/B" should pass through to B's "/" mapping.
Additional mappings, which again I don't necessarily know about in advance, should also pass through respectively - so "localhost:8080/A/items" should pass through to A's "/items", etc.
I do not have the source code for A or B, only .jar files.
For security, A and B should have separate scopes with no knowledge of each other or ability to interact with each other. The whole setup should behave as if A and B were separate "inner" servers within my "outer" localhost server.
Can this be achieved via a Spring Boot/Web wrapper or gateway app, or some other way?
You could use spring boot with Zuul as a third app, running on 8080, which has routes setup for A and B similar to what you described.
zuul:
routes:
app-A:
path: /A/**
url: http://localhost:8081/
app-B:
path: /B/**
url: http://localhost:8082/
That configuration (application.yml) of your third app would point "A" traffic to port 8081 and "B" traffic to port 8082.
This is quick and dirty, but should get you started.
Alternatively, you could use spring cloud gateway, to get a similar type of setup with the additional ability to do sockets/reactive.

Zuul routing doesn't work, gives 404 : Spring Boot+ Cloud+ Zuul

I am working on a flow where I have ng4+boot app running on https://host_a:8080 and a backend service at https://host_b:8080 with some APIs.
I have RestController/Path at both the hosts, i.e. I need some urls to hit localhost (host_a) and others to host_b.
In application.yml, I have tried almost all possible combinations of Zuul routes but still getting 404 for all host_b rest APIs. host_a APIs work well.
Note: We have this working when there is no rest API on host_a and no custom filter on host_a.
Is there something wrong working with filter? I don't see any log from zuul filter now after I added this controller to host_a
I am aware that I can use forward property to route to localhost which works well. But somehow host_b rest all gives 404 error.
My implementation requirements-
http://host_a:8080/api/abc/user to hit at localhost i.e. host_a
http://host_a:8080/api/xyz/getall to hit at host_b
Important- Need a custom zuul filter which adds certain headers to request before it's routed to host_b as explained in point 2. - Already at place, but cannot see logs inside it now.
What I tried already-
zuul:
routes:
xyz:
path: /api/xyz/**
url: http://host_b:8080/api/xyz
I tried almost everything, using prefix, strip-prefix, only host in url, using forward for local routing, etc. Nothing works.
Kindly help me with the possible causes I may be ignoring or if missing something?
Thanks in advance.
Finally, I was able to resolve issues.
1. I had to change jersey #Path to spring #RestController
2. Changed Zuul Filter order from 1 to 999.
Works well now.

Spring cloud config properties not honouring config properties

I wish to use consul strictly as a config source.
I am using spring-cloud-consul-config to get my config.
I am using git2consul to load files into consul and read them.
As per the spring cloud documentation I have added the following to my build.gradle
compile ("org.springframework.cloud:spring-cloud-starter-consul-config")
and have the following in my application.properties
spring.application.name=test-service
spring.cloud.consul.config.enabled=true
spring.cloud.consul.enabled=true
spring.cloud.consul.config.format=FILES
The problem I am facing is that the expected properties are not being loaded into the ConfigurationProperties beans. On further debugging in the ConsulPropertySourceLocator::locate(Environment environment) method, I see that the this.properties object is still loaded with KEY_VALUE enum.
This led me to ConsulConfigBootstrapConfiguration class, where the ConsulConfigProperties bean is being instantiated using a constructor.
Is this the problem or do I have something wrong in my setup.
If someone has a working setup of git2consul and spring cloud config, please can you point me to it for reference.
These values that you have in application.properties
spring.application.name=test-service
spring.cloud.consul.config.enabled=true
spring.cloud.consul.enabled=true
spring.cloud.consul.config.format=FILES
need to be in bootstrap.properties.

phalcon include modules in rest

I am trying to include a module in Phalcon Micro Application. Is that possible?
I have a structure like this
common/
components/
...
modules/
system
components
...
controllers
...
rest
components
...
controllers
...
www
controllers
...
www/
index.php -> Loads /Phalcon/Mvc/Application($di);
api/
index.php -> Loads /Phalcon/Mvc/Micro($di);
The www registers the modules from config
I want the api to register the rest module from config and include the controllers and the components of that module. Is that possible?
Thanks,
Gasim
Obviously all is possible !
If you want to keep your structure with application+micro I think the best way is to create 3 configs.
A first config that is common with both of api and www
A second one which is loaded only by your www with its one router
A thirds one which is loaded only by your api with its one microrouter and which redefines the different paths to the rest module.
If you want just to use a multi module application with a single config file, then I can advice you to use the domain recognition in your router thanks to the setHostName() method.
Then in your config file you define an api hostname and a www hostname that you use everytime. You may also put them in global constant for more convenience.
// an api get route
$router->add("/getsomething",...)
->via("GET")
->setHostname(MyApp::HOSTNAME_API);
// an api post route
$router->add("/postsomething",...)
->via("POST")
->setHostname(MyApp::HOSTNAME_API);
// a www route
$router->add("/",...)->setHostname(MyApp::HOSTNAME_WEB);
I am trying to include a module in Phalcon Micro Application. Is that possible?
Yes, no problem!
I want the api to register the rest module from config and include the controllers and the components of that module. Is that possible?
Looking at your description and structure I understand it as you would like to separate the configuration of the www module and api module. This will work fine and you only need to include your api configuration in www/index.php (since that is where you start your application and where all your requests will go). Good luck!