我正在尝试通过 jms (activemq) 发送消息,但我希望它采用 ssl 协议(protocol)。 它现在实际上在 tcp 中工作。
我使用 jndi,带有一个虚拟主题和 2 个队列。有人可以帮我吗,我试过了,但我卡住了,服务器无法启动:
http://activemq.apache.org/how-do-i-use-ssl.html
谢谢
编辑:日志显示:“对实体“needClientAuth”的引用必须以“;”结尾分隔符。”
最佳答案
我会回答我自己的问题:
首先在 ..../apache-activemq-5.11.1/conf/activemq.xml 中:
<transportConnectors>
<transportConnector name="ssl" uri="ssl://0.0.0.0:61617?trace=true&needClientAuth=true"/>
</transportConnectors>
不要忘记 & amp;(没有空格)这是服务器端的阻塞。在 activemq 页面上没有写。也不要忘记打开您的端口。这里 (61617)
还在activemq.xml里面
<sslContext>
<sslContext keyStore="file:${activemq.base}/conf/amq-server.ks"
keyStorePassword="PASSWORD"
trustStore="file:${activemq.base}/conf/amq-server.ts"
trustStorePassword="PASSWORD" />
</sslContext>
重启JMS;这次应该可以了。现在您的服务器端没问题,让我们去客户端吧。
我已经在 activemq ..../apache-activemq-5.11.1/conf 中完成了此操作:(按照要求、名称、通过等...)。
## Create a keystore for the broker SERVER
$ keytool -genkey -alias amq-server -keyalg RSA -keysize 2048 -validity 90 -keystore amq-server.ks
## Export the broker SERVER certificate from the keystore
$ keytool -export -alias amq-server -keystore amq-server.ks -file amq-server_cert
## Create the CLIENT keystore
$ keytool -genkey -alias amq-client -keyalg RSA -keysize 2048 -validity 90 -keystore amq-client.ks
## Import the previous exported broker's certificate into a CLIENT truststore
$ keytool -import -alias amq-server -keystore amq-client.ts -file amq-server_cert
## If you want to make trusted also the client, you must export the client's certificate from the keystore
$ keytool -export -alias amq-client -keystore amq-client.ks -file amq-client_cert
## Import the client's exported certificate into a broker SERVER truststore
$ keytool -import -alias amq-client -keystore amq-server.ts -file amq-client_cert
然后我在https://winscp.net/eng/index.php的帮助下下载了我的“amq-client.ts”和“amq-client.ks”从我的服务器到我的电脑(我在 windows 上开发,在 linux 上开发服务器)。
我在eclipse 中使用这两个文件作为源。 (我不会解释如何操作)。
最后在 eclipse 中我只需要改变一件事,我必须用 ActiveMQSslConnectionFactory 替换 QueueConnectionFactory:
所以我擦掉了
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx
.lookup("jms/ConnectionFactory");
取而代之的是:
ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory(url);
try {
connectionFactory.setTrustStore(CLIENT_TS_FILE);
connectionFactory.setTrustStorePassword("PASSWORD asked while TS file made");
connectionFactory.setKeyStore(CLIENT_KS_FILE);
connectionFactory.setKeyStorePassword("PASSWORD asked while KS file made");
} catch (Exception e) {
throw new MotorException(
"JMS Connection Failed (Trust store or key store weren't found) : ",
e);
}
至少对于 activemq 和 ssl,互联网上的内容很少,它可能对某人有帮助。
关于java - 如何在ssl中激活mq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32696121/