这个问题可能由于ActiveMQ SSL连接在发送完消息后未正确关闭连接而导致的。 在Producer发送完消息后,需要显式地调用stop()方法,以确保关闭连接。 以下是一些示例代码:
ConnectionFactory factory = new ActiveMQSslConnectionFactory(brokerUrl);
SSLContext sslContext = SSLContext.getInstance("TLS");
KeyStore ks = KeyStore.getInstance("jks");
ks.load(new FileInputStream(new File(keystorePath)),
keystorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, keystorePassword.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
factory.setSslContext(sslContext);
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic destination = session.createTopic(topicName);
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("Hello");
producer.send(message);
producer.close(); // 显式关闭
connection.stop();
connection.close();
像这样,每次Producer发送完消息后,都需要显式地调用stop()方法来关闭连接。这将确保ActiveMQ SSL连接正确关闭,并避免出现“outbound has closed, ignore outbound alert message: close_notify”错误。