Skip to content

Connection Polling with Spring Web Socket over STOMP with external Broker #33988

@aliahmadcse

Description

@aliahmadcse

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comin: messagingIssues in messaging modules (jms, messaging)in: webIssues in web modules (web, webmvc, webflux, websocket)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions