Currently, I have Set up spring websockets over STOMP and messages are routed to RabbitMQ and it acts as an external broker. My current setup looks like below:
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry
.addEndpoint("/connect")
.setAllowedOrigins("*");
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setPreservePublishOrder(true)
.setApplicationDestinationPrefixes(APP_PREFIXES)
.enableStompBrokerRelay(BROKER_PREFIXES)
.setUserDestinationBroadcast("/topic/unresolved.user.dest")
.setUserRegistryBroadcast("/topic/registry.broadcast")
.setTaskScheduler(getHeartbeatScheduler())
.setRelayHost(rabbitMQHost)
.setRelayPort(rabbitMQPort)
.setClientLogin(rabbitMQUsername)
.setClientPasscode(rabbitMQPassword)
.setSystemLogin(rabbitMQUsername)
.setSystemPasscode(rabbitMQPassword)
.setVirtualHost(rabbitMQVirtualHost);
registry.configureBrokerChannel()
.interceptors(new LoggingInterceptor(), new EscapeSlashesInterceptor())
.taskExecutor().corePoolSize(1).maxPoolSize(MAX_WORKERS_COUNT).queueCapacity(TASK_QUEUE_SIZE);
}
Whenever a client send a /connect request, my application makes a new connection to the rabbitMQ broker and it happens for each client. Let say, there are 10 clients, so there will be 10 connections to the rabbitMQ broker. I want to introduce a connection pooling mechanism here, so I can limit the number of connections to the broker and reuse them when needed. I searched the web but couldn't find any relevant solution.
Does the framework provide such mechanism or any other possible way to achieve the same. Any help in regard is highly appreciated. Thank you.
Comment From: rstoyanchev
The underlying Reactor Netty TcpClient has connection pooling. That said keep in mind each connected client needs to have its own connection to the broker for the duration of its WebSocket session, so the number of TCP connections equals the number of connected WebSocket clients.