spring5-webflux-rest icon indicating copy to clipboard operation
spring5-webflux-rest copied to clipboard

Expose particular REST controller on specific port using Spring Webflux

Open amolai opened this issue 3 years ago • 0 comments

Working on a spring boot based application and using spring webflux, we are exposing 3 ports

  1. server.port

  2. management.server.port (actuator) and are planning to expose another port called as admin port.

We want to expose a specific REST controller on this admin port which will be private. This api will provide all the admin level configuration and will not be available publicly to the user.

Note: We don't want to expose api on actuator port. Need to open a new port.

Using the following code to open a new port by starting a new server instance.

`@Configuration public class NettyServerForAdminPort {

@Value("${admin.port}")
private Integer adminPort;

@Autowired
HttpHandler httpHandler;

WebServer http;

@PostConstruct
public void start() {
  ReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(8081);
  this.http = factory.getWebServer(this.httpHandler);
  this.http.start();
}

@PreDestroy
public void stop() {
  this.http.stop();
}

}`

Spring boot, webflux doesn't provide an out of box solution for this, can this be achieved using RouterFunction ?? Any insights here would be helpful.

Thank you

amolai avatar Sep 07 '22 09:09 amolai