我会回答我自己的问题:
首先在 ..../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”从我的服务器下载到我的 PC(我在 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 来说,互联网上的内容很少,它可能会对某人有所帮助。