Reputation: 1931
How do you configure Spring Boot with Reactor Netty to listen on two separate ports (in addition to the Actuator port) and tie separate @RestController
's to each?
Here's the use case: I have a single bounded context that has four RESTful API calls. Two will be externally exposed, two cannot be. Each pair will be secured in their own manner, but we want an additional layer of protection such that the internal calls are not externally routable. Platforms like Kubernetes support this by only routing traffic to ports that we specifically expose.
So I would like Reactor Netty to listen on the following ports and route only the appropriate requests to each port:
8080
requests are responded to only by the ExternalRestController
class (default config or easily overridden with server.port=8080
).8081
requests are responded to only by the InternalRestController
class.8082
requests are responded to by SpringBoot's Actuator support (easily configured with management.server.port=8082
)If this is not possible with Spring Boot's annotation model using @RestController
annotations, I would consider using the new RouterFunction
support.
Upvotes: 2
Views: 2486
Reputation: 116091
There’s no out-of-the-box support in Spring Boot for mapping individual controllers to individual ports in Spring MVC, WebFlux, or WebFlux.Fn. It is possible, as shown by the Actuator’s separate management port, but it will require a reasonably large amount of work.
To run on a separate port, the Actuator uses a child application context with a separate embedded web server configured to listen on a separate port. You could mimic this arrangement in your own application using Spring Boot’s source as inspiration. ManagementContextAutoConfiguration
is a good place to start.
Upvotes: 2