如何使用 spring-messaging-5.1.* 连接 stomp+ssl broker?
How to use spring-messaging-5.1.* to connect stomp+ssl broker?
我想在 websocket 上使用 stomp 并打算与 Amazon MQ 集成,但是 Amazon MQ 默认使用 stomp+ssl,然后我遇到了问题。
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Autowired
private ActiveMQProperties activeMQProperties;
/**
* Register STOMP endpoints mapping each to a specific URL and (optionally)
* enabling and configuring SockJS fallback options.
*
* @param registry
*/
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/endpoint").setAllowedOrigins("*");
}
/**
* Configure message broker options.
*
* @param registry
*/
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setVirtualHost(activeMQProperties.getHost())
.setRelayHost(activeMQProperties.getHost())
.setRelayPort(activeMQProperties.getPort())
.setSystemLogin(activeMQProperties.getUser())
.setSystemPasscode(activeMQProperties.getPassword())
.setClientLogin(activeMQProperties.getUser())
.setClientPasscode(activeMQProperties.getPassword());
}}
ReactorNettyTcpClient是spring-messaging-5.1.*中TcpOperations的实现,怎么支持SSL?
最近在使用 ActiveMQ 时遇到了这个问题。
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
ReactorNettyTcpClient<byte[]> client = new ReactorNettyTcpClient<>(builder -> {
builder.port(activeMQProperties.getPort())
.host(activeMQProperties.getHost())
.sslSupport(opts -> { /* set SSL options here */})
}, new StompReactorNettyCodec());
registry.setApplicationDestinationPrefixes("/app");
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setVirtualHost(activeMQProperties.getHost())
.setSystemLogin(activeMQProperties.getUser())
.setSystemPasscode(activeMQProperties.getPassword())
.setClientLogin(activeMQProperties.getUser())
.setClientPasscode(activeMQProperties.getPassword())
.setTcpClient(client);
}}
很有魅力。我需要做的一件事是稍微更新 TCP 客户端创建:
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
ReactorNettyTcpClient<byte[]> tcpClient = new ReactorNettyTcpClient<>(configurer -> configurer
.host(properties.getRelayHost())
.port(properties.getRelayPort())
.secure(), new StompReactorNettyCodec());
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setSystemLogin(properties.getClientLogin())
.setSystemPasscode(properties.getClientPasscode())
.setClientLogin(properties.getClientLogin())
.setClientPasscode(properties.getClientPasscode())
.setTcpClient(tcpClient);
registry.setApplicationDestinationPrefixes("/app");
}
依赖关系:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/>
</parent>
.
.
.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-stomp</artifactId>
<version>5.16.2</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>1.0.8</version>
</dependency>
我想在 websocket 上使用 stomp 并打算与 Amazon MQ 集成,但是 Amazon MQ 默认使用 stomp+ssl,然后我遇到了问题。
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Autowired
private ActiveMQProperties activeMQProperties;
/**
* Register STOMP endpoints mapping each to a specific URL and (optionally)
* enabling and configuring SockJS fallback options.
*
* @param registry
*/
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/endpoint").setAllowedOrigins("*");
}
/**
* Configure message broker options.
*
* @param registry
*/
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setVirtualHost(activeMQProperties.getHost())
.setRelayHost(activeMQProperties.getHost())
.setRelayPort(activeMQProperties.getPort())
.setSystemLogin(activeMQProperties.getUser())
.setSystemPasscode(activeMQProperties.getPassword())
.setClientLogin(activeMQProperties.getUser())
.setClientPasscode(activeMQProperties.getPassword());
}}
ReactorNettyTcpClient是spring-messaging-5.1.*中TcpOperations的实现,怎么支持SSL?
最近在使用 ActiveMQ 时遇到了这个问题。
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
ReactorNettyTcpClient<byte[]> client = new ReactorNettyTcpClient<>(builder -> {
builder.port(activeMQProperties.getPort())
.host(activeMQProperties.getHost())
.sslSupport(opts -> { /* set SSL options here */})
}, new StompReactorNettyCodec());
registry.setApplicationDestinationPrefixes("/app");
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setVirtualHost(activeMQProperties.getHost())
.setSystemLogin(activeMQProperties.getUser())
.setSystemPasscode(activeMQProperties.getPassword())
.setClientLogin(activeMQProperties.getUser())
.setClientPasscode(activeMQProperties.getPassword())
.setTcpClient(client);
}}
很有魅力。我需要做的一件事是稍微更新 TCP 客户端创建:
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
ReactorNettyTcpClient<byte[]> tcpClient = new ReactorNettyTcpClient<>(configurer -> configurer
.host(properties.getRelayHost())
.port(properties.getRelayPort())
.secure(), new StompReactorNettyCodec());
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setSystemLogin(properties.getClientLogin())
.setSystemPasscode(properties.getClientPasscode())
.setClientLogin(properties.getClientLogin())
.setClientPasscode(properties.getClientPasscode())
.setTcpClient(tcpClient);
registry.setApplicationDestinationPrefixes("/app");
}
依赖关系:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/>
</parent>
.
.
.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-stomp</artifactId>
<version>5.16.2</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>1.0.8</version>
</dependency>