如何在ssl中激活mq

How to activemq in ssl

我正在尝试通过 jms (activemq) 发送消息,但我希望它采用 ssl 协议。 它现在实际上在 tcp 中工作。

我使用 jndi,有一个虚拟主题和 2 个队列。有人可以帮我吗,我试过了,但我卡住了,服务器无法启动:

http://activemq.apache.org/how-do-i-use-ssl.html

感谢

编辑:日志显示:"The reference to entity "needClientAuth" 必须以 ';' 结尾分隔符。”

我会回答我自己的问题:

首先里面..../apache-activemq-5.11.1/conf/activemq.xml :

<transportConnectors>
  <transportConnector name="ssl" uri="ssl://0.0.0.0:61617?trace=true&amp;needClientAuth=true"/>
</transportConnectors>

不要忘记 & amp;(没有 space),这就是在服务器端阻塞的原因。在 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 上开发,在 [=47 上开发服务器) =]).

我在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 它可能对某人有所帮助。