I have requirements to route to different services based on the HTTP method being used. We are using CQRS and microservices, and the architecture has split the commands and queries into separate services. The command service accepts POST, PUT, and PATCH, and the query side accepts just GET. Both operate on the same path (eg, command processes POST http://cmd-service/song, queries process GET http://query-service/songs).
Using the samples provided in http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html#netflix-zuul-reverse-proxy, I can write something like this in my application.yml:
zuul:
routes:
songs-cmd:
path: /songs
serviceId: song-cmd-service
songs-query:
path: /songs
serviceId: song-query-service
unrelated-service:
path: /unrelated-path
This obviously won't work, since I have 2 services mapped to the same path. However, I'd like to be able to add in method filtering to the configuration as follows:
zuul:
routes:
songs-cmd:
path: /songs
serviceId: song-cmd-service
methods:
- POST
- PUT
- PATCH
songs-query:
path: /songs
serviceId: song-query-service
methods:
- GET
unrelated-service:
path: /unrelated-path
This would allow consumers to route based on HTTP method. If I can't do this, I know my options are to add a class that extends from ZuulFilter to provide these capabilities, but I'd rather keep as much of this in configuration as possible. Also, for any services that don't need to be filtered by method, the omission of methods would default to allowing all HTTP methods.
If I were to work on this and submit a PR, what is the likelihood of this being accepted?
We want to have enhanced routing capabilities for s-c-n-zuul, such as headers, domain, and methods like you've mentioned. I'd hesitate to start a PR for this as we want to try and incorporate the different strategies coherently for the Dalston release train.
What's the ETA for the Dalston release train?
end of 2016
starting discussion on https://github.com/spring-cloud/spring-cloud-netflix/issues/1235
Is this still planned for Dalston release?
not currently
Having the HTTP method for enhanced would be super helpful! @spencergibb .......sounds like there was a plan to utilize multiple new ways for enhanced routing. Curious, this still in the plans for an upcoming release? We just began using Zuul for our gateway needs and having to use Filters to route requests that require interrogating the HTTP method.
It is not.
Are there any updates here?
No
any updates?
If there are any updates they will be posted here.
Sorry to clutter the tracker but... @zshift did you find an alternative pattern/solution to your initial question? I'm trying to do the exact same thing with Zuul and finding resources for guidance a bit lacking...
any updates?
Folks, please stop asking for updates, when there are, you will see them here.
@spencergibb is there any advice on implementing this? I'm interested in decisions made (if any) because I'm thinking of doing it.
@peavers My apologies for the delay. I've since moved to a different company, so I don't have access to the source code I originally worked on. I added a separate configuration section that mapped the zuul route keys to allowed http methods on each route. Eg,
zuul:
routes:
songs-cmd:
path: /songs
serviceId: song-cmd-service
songs-query:
path: /songs
serviceId: song-query-service
unrelated-service:
path: /unrelated-path
zuul-method-map:
routes:
songs-cmd:
- PUT
- POST
- DELETE
songs-query:
- GET
unrelated-service:
- GET
Then I added a filter similar to https://stackoverflow.com/questions/47856575/how-to-make-zuul-dynamic-routing-based-on-http-method-and-resolve-target-host-by
That would read both configurations, map them together at startup, then route based on the incoming path and method. However, we found a bug just before I left that involved this new filter I added preventing other filters from running correctly. It was likely because of filter order and/or filter type, but I never got around to resolving that. I hope this helps out, and I'm sorry I can't provide more clear instructions at this time.
Did someone had the chance to take a look on my PR? Thx!
It's holidays, please be patient
Any update for this item? Or any suggestion how to create routing base on HttpMethod?
This module has entered maintenance mode. This means that the Spring Cloud team will no longer be adding new features to the module. We will fix blocker bugs and security issues, and we will also consider and review small pull requests from the community.
Most helpful comment
Folks, please stop asking for updates, when there are, you will see them here.