春天引导+的Spring Web插槽+ RabbitMQ的STOMP网站

问题描述 投票:3回答:1

我的工作我的应用程序添加实时通知

我已经做了POC与 - 春季启动 - 春天的WebSocket - SockJS - RabbitMQ的STOMP插件

我读到RabbitMQ Web STOMP 和想要做的是POC。但它说,由于对SockJS网页套接字仿效版本3.7支持已被删除。

是否有春天的WebSocket + RabbitMQ的STOMP网站有或没有任何SockJS例子。

请帮忙。

参考链接:

http://www.rabbitmq.com/stomp.html

http://www.rabbitmq.com/web-stomp.html

https://spring.io/guides/gs/messaging-stomp-websocket/

java spring-boot rabbitmq spring-websocket sockjs
1个回答
6
投票

@ n.sharvarish ...首先创建了这样一个的RabbitMQ的WebSocket配置类...

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);
    @Value("${spring.rabbitmq.username}")
    private String userName;
    @Value("${spring.rabbitmq.password}")
    private String password;
    @Value("${spring.rabbitmq.host}")
    private String host;
    @Value("${spring.rabbitmq.port}")
    private int port;
    @Value("${endpoint}")
    private String endpoint;
    @Value("${destination.prefix}")
    private String destinationPrefix;
    @Value("${stomp.broker.relay}")
    private String stompBrokerRelay;
    @Override
    public void configureMessageBroker(final MessageBrokerRegistry config) {
        config.enableStompBrokerRelay(stompBrokerRelay).setRelayHost(host).setRelayPort(port).setSystemLogin(userName).setSystemPasscode(password);
        config.setApplicationDestinationPrefixes(destinationPrefix);
    }
    @Override
    public void registerStompEndpoints(final StompEndpointRegistry registry) {
        registry.addEndpoint(endpoint).setAllowedOrigins("*").withSockJS();
    }
}

然后......您要使用..这样使用上述配置类..

@Autowired
SimpMessagingTemplate template

template.convertAndSend(destinationurl, object);

并配置上面的用户名和密码,并全部由application.properties

© www.soinside.com 2019 - 2024. All rights reserved.