使用RabbitMQ的SimpMessagingTemplate.convertAndSend工作速度非常慢

13

我正在使用Spring STOMP通过RabbitMQ进行Websocket通信。一切都正常,但是simpMessagingTemplate.convertAndSend函数执行非常慢,调用可能需要2-10秒(同步地,阻塞线程)。可能的原因是什么?

RabbitTemplate.convertAndSend不到1秒,但我需要使用Websocket上的STOMP。

更新

我尝试使用ActiveMQ并得到相同的结果。convertAndSend需要2-10秒。

ActiveMQ具有默认配置。

Web socket配置:

@Configuration
@EnableWebSocket
@EnableWebSocketMessageBroker
class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableStompBrokerRelay("/topic", "/queue", "/exchange");
        config.setApplicationDestinationPrefixes("/topic", "/queue"); // prefix in client queries
        config.setUserDestinationPrefix("/user");
    }

    @Override
    void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/board").withSockJS()
    }

    @Override
    void configureWebSocketTransport(WebSocketTransportRegistration registration) {
        registration.setMessageSizeLimit(8 * 1024);
    }
}

你正在使用哪个Spring版本?能否举个转换前/后的消息例子? - Brian Clozel
有点难为情,但你能否尝试回答一下我的这个问题?链接在此:https://stackoverflow.com/q/55016259/5051731 - YetAnotherBot
1个回答

9

问题已解决。这是io.projectreactor库版本2.0.4.RELEASE中的错误。我将其更改为2.0.8.RELEASE,问题已经解决。现在发送消息需要约50毫秒。

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
        <version>2.0.8.RELEASE</version>
    </dependency>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接