1. ActiveMQ的根目录我们称为${activemq.base}
。然后把上篇生成的证书复制到mq的安装目录下
2. 修改conf/acivemq.xml文件
<sslContext keyStore="file:${activemq.base}/conf/broker1.ks"
keyStorePassword="allen"
trustStore="file:${activemq.base}/conf/broker1.ts"
trustStorePassword="allen"
/>
</sslContext>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:35672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<!-- <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/> -->
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ssl" uri="ssl://0.0.0.0:62617?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
3.启动验证:
4. 客户端测试:
public class ConsumerAndProducerSSL {
public static void main(String[] args) {
// ssl
ActiveMQSslConnectionFactory connectionFactory = null;
Connection conn = null;
Session session = null;
MessageConsumer consumer = null;
try {
// 1、创建连接工厂
connectionFactory = new ActiveMQSslConnectionFactory("ssl://localhost:62617?socket.verifyHostName=false");
connectionFactory.setTrustStore("client1.ts");
connectionFactory.setTrustStorePassword("allenxx");
// 2、创建连接对象
conn = connectionFactory.createConnection();
conn.start();
// 3、 创建session
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
// 4、创建点对点接收的目标
Destination destination = session.createQueue("queue1");
// 5、创建生产者消息
MessageProducer producer = session.createProducer(destination);
// 设置生产者的模式,有两种可选
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 6、创建一条消息
String text = "Hello world!";
TextMessage message = session.createTextMessage(text);
// 7、发送消息
producer.send(message);
// 8、创建消费者消息
consumer = session.createConsumer(destination);
// 9、接收消息
Message consumerMessage = consumer.receive();
if (consumerMessage instanceof TextMessage) {
System.out.println("收到文本消息:" + ((TextMessage) consumerMessage).getText());
} else {
System.out.println(consumerMessage);
}
consumer.close();
session.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
5.到mq页面验证:connections(java代码打断点,否则运行完就看不到:只显示当前连接的)