大佬教程收集整理的这篇文章主要介绍了Spring Boot SSL TCPClient〜StompBrokerRelayMessageHandler〜ActiveMQ〜Undertow,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
该StompbrokerRelaymessageHandler
有一个TcpClIEnt的属性可以设置。但是,看起来我们没有通过WebSocketmessagebrokerConfigurer
设置来公开它。
您可以删除@EnableWebSocketmessagebroker
并扩展DelegaTingWebSocketmessagebrokerConfiguration
。实际上是一样的,但是您现在直接从提供所有bean的配置类扩展。
这样,您就可以覆盖stompbrokerRelaymessageHandler()
Bean并直接设置其TcpClIEnt属性。只要确保覆盖方法标记为即可@Bean
。
我正在尝试基于运行ActiveMQ的Spring
Websocket演示构建一个Websocket消息传递应用程序,该ActiveMQ作为Undertow的STOMP消息代理。该应用程序在不安全的连接上运行良好。但是,我在配置STOMP
Broker Relay以通过SSL连接转发时遇到困难。
如Spring WebSocket文档中所述&Hellip;
此外,文档指出我对Reactor-net有依赖性&Hellip;
问题是我当前的实现未通过SSL
初始化NettyTCPClient,因此ActiveMQ连接失败,并出现SSLException。
[r.i.n.i.n.t.NettyTcpClient:307] » CONNECTED:
[id: 0xcfef39e9,/127.0.0.1:17779 => localhost/127.0.0.1:8442]
...
[o.a.a.b.TransportConnection.Transport:245] »
Transport Connection to: tcp://127.0.0.1:17779 failed:
javax.net.ssl.SSLException: Unrecognized SSL message,plaintext connection?
...
因此,我尝试研究Project Reactor
Docs来设置连接的SSL选项,但是我没有成功。
此时,我发现StompBrokerRelaymessageHandler默认在Reactor2TcpClient中初始化NettyTCPClient,但它似乎不可配置。
协助将不胜感激。
社会科学中心
spring.activemq.in-memory=true
spring.activemq.pooled=false
spring.activemq.broker-url=stomp+ssl://localhost:8442
server.port=8443
server.ssl.enabled=true
server.ssl.protocol=tls
server.ssl.key-alias=undertow
server.ssl.key-store=classpath:undertow.jks
server.ssl.key-store-password=xxx
server.ssl.trust-store=classpath:undertow_certs.jks
server.ssl.trust-store-password=xxx
@H_674_36@//...
@Configuration
@EnableWebSocketmessageBroker
public class WebSocketConfig extends AbstractWebSocketmessageBrokerConfigurer {
private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);
private final static String KEYSTORE = "/activemq.jks";
private final static String KEYSTORE_PASS = "xxx";
private final static String KEYSTORE_TYPE = "JKS";
private final static String TRUSTSTORE = "/activemq_certs.jks";
private final static String TRUSTSTORE_PASS = "xxx";
private static String getBindLOCATIOn() {
return "stomp+ssl://localhost:8442?transport.needClientAuth=false";
}
@Bean(initMethod = "start",destroymethod = "stop")
public SslBrokerservice activeMQBroker() throws Exception {
final SslBrokerservice service = new SslBrokerservice();
service.setPersistent(false);
Keymanager[] km = Securitymanager.getKeymanager();
TrustManager[] tm = Securitymanager.getTrustManager();
service.addSslConnector(getBindLOCATIOn(),km,tm,null);
final ActiveMQTopic topic = new ActiveMQTopic("jms.topic.test");
service.setDesTinations(new ActiveMQDesTination[]{topic});
return service;
}
@Override
public void configuremessageBroker(messageBrokerRegistry config) {
config.enableStompBrokerRelay("/topic").setRelayHost("localhost").setRelayPort(8442);
config.setApplicationDesTinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/welcome").withSockJS();
registry.addEndpoint("/test").withSockJS();
}
private static class Securitymanager {
//elided...
}
}
@Configuration
public class WebSocketConfig extends DelegaTingWebSocketmessageBrokerConfiguration {
...
@Bean
public AbstractBrokermessageHandler stompBrokerRelaymessageHandler() {
StompBrokerRelaymessageHandler handler = (StompBrokerRelaymessageHandler) super.stompBrokerRelaymessageHandler();
ConfigurationReader reader = new StompClientDispatcherConfigReader();
Environment environment = new Environment(reader).assignErrorJournal();
TcpOperations<byte[]> client = new Reactor2TcpClient<>(new StompTcpClientSpecFactory(environment,"localhost",8443));
handler.setTcpClient(client);
return handler;
}
}
@H_674_36@private static class StompTcpClientSpecFactory
implements NetStreams.TcpClientFactory<message<byte[]>,message<byte[]>> {
private static final Logger log = LoggerFactory.getLogger(StompTcpClientSpecFactory.class);
private final String host;
private final int port;
private final String KEYSTORE = "src/main/resources/tcpclient.jks";
private final String KEYSTORE_PASS = "xxx";
private final String KEYSTORE_TYPE = "JKS";
private final String TRUSTSTORE = "/src/main/resources/tcpclient_certs.jks";
private final String TRUSTSTORE_PASS = "xxx";
private final String TRUSTSTORE_TYPE = "JKS";
private final Environment environment;
private final Securitymanager tcpManager = new Securitymanager
.SSLBuilder(KEYSTORE,KEYSTORE_PASS)
.keyStoreType(KEYSTORE_TYPE)
.trustStore(TRUSTSTORE,TRUSTSTORE_PASS)
.trustStoreType(TRUSTSTORE_TYPE)
.build();
public StompTcpClientSpecFactory(Environment environment,String host,int port) {
this.environment = environment;
this.host = host;
this.port = port;
}
@Override
public Spec.TcpClientSpec<message<byte[]>,message<byte[]>> apply(
Spec.TcpClientSpec<message<byte[]>,message<byte[]>> tcpClientSpeC) {
return tcpClientSpec
.ssl(new SslOptions()
.sslProtocol("TLS")
.keystoreFile(tcpManager.getKeyStore())
.keystorePasswd(tcpManager.getKeyStorePass())
.trustManagers(tcpManager::getTrustManager)
.trustManagerPasswd(tcpManager.getTrustStorePass()))
.codec(new Reactor2StompCodec(new StompEncoder(),new StompDecoder()))
.env(this.environment)
.dispatcher(this.environment.getCachedDispatchers("StompClient").get())
.connect(this.host,this.port);
}
}
以上是大佬教程为你收集整理的Spring Boot SSL TCPClient〜StompBrokerRelayMessageHandler〜ActiveMQ〜Undertow全部内容,希望文章能够帮你解决Spring Boot SSL TCPClient〜StompBrokerRelayMessageHandler〜ActiveMQ〜Undertow所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。