gpt4 book ai didi

java - Spring Boot + Spring Web Socket + RabbitMQ Web STOMP

转载 作者:搜寻专家 更新时间:2023-11-01 01:59:56 27 4
gpt4 key购买 nike

我正在努力在我的应用程序中添加实时通知

我已经完成了POC- Spring Boot - Spring 网络套接字- socks - RabbitMQ STOMP 插件

我读到了 RabbitMQ Web STOMP 并想对此进行 POC。但它说从 3.7 版开始,对 SockJS websocket 仿真的支持已被删除。

是否有使用或不使用 SockJS 的 Spring WebSocket + RabbitMQ Web STOMP 的示例。

请帮忙。

引用链接:

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

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

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

最佳答案

@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

关于java - Spring Boot + Spring Web Socket + RabbitMQ Web STOMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51745211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com