我正在尝试让 ActiveMQ Artemis 在我的计算机上本地运行。
我创建了一个小程序(在 Spring Boot 应用程序中启动),它为 ActiveMQ Artemis 创建 JMS
ConnectionFactory
,创建一个主题,然后发送有关该主题的消息。
public void send() throws Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL("tcp://localhost:61616");
connectionFactory.setUser("artemis");
connectionFactory.setPassword("artemis");
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
Topic myTopic = new ActiveMQTopic("myTopic");
System.out.println("before");
jmsTemplate.convertAndSend(myTopic, "my message", m -> {
m.setStringProperty("test", "test");
return m;
});
System.out.println("after");
}
在我的
docker-compose
文件中,我根据如下配置启动 Artemis 容器:
akom-activemq-artemis:
image: apache/activemq-artemis
ports:
- "61616:61616"
当我运行程序时,我收到一个如下所示的异常:
before
after
13:34:01.489 [RMI TCP Connection(3)-172.17.192.1] WARN o.s.b.actuate.jms.JmsHealthIndicator - JMS health check failed
jakarta.jms.JMSSecurityException: AMQ229031: Unable to validate user from /172.18.0.1:48222. Username: null; SSL certificate subject DN: unavailable
at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:558)
at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:450)
at org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtocolManager.createSessionContext(ActiveMQClientProtocolManager.java:308)
at org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtocolManager.createSessionContext(ActiveMQClientProtocolManager.java:256)
at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createSessionChannel(ClientSessionFactoryImpl.java:1402)
at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:733)
at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createSession(ClientSessionFactoryImpl.java:314)
at org.apache.activemq.artemis.jms.client.ActiveMQConnection.authorize(ActiveMQConnection.java:650)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:933)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:291)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:286)
at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:425)
at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:352)
at org.springframework.jms.connection.SingleConnectionFactory.getConnection(SingleConnectionFactory.java:327)
at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:242)
at org.springframework.boot.actuate.jms.JmsHealthIndicator.doHealthCheck(JmsHealthIndicator.java:51)
如果我查看 Docker 日志,就会看到消息通过,并且显示与我的程序中相同的错误消息:
2024-05-04 11:22:15,575 INFO [org.apache.activemq.artemis] AMQ241001: HTTP Server started at http://0.0.0.0:8161
2024-05-04T11:22:15.575723223Z 2024-05-04 11:22:15,575 INFO [org.apache.activemq.artemis] AMQ241002: Artemis Jolokia REST API available at http://0.0.0.0:8161/console/jolokia
2024-05-04T11:22:15.575744578Z 2024-05-04 11:22:15,575 INFO [org.apache.activemq.artemis] AMQ241004: Artemis Console available at http://0.0.0.0:8161/console
2024-05-04T11:23:34.101125937Z 2024-05-04 11:23:34,100 WARN [org.apache.activemq.artemis.core.server] AMQ222216: Security problem while authenticating: AMQ229031: Unable to validate user from /172.18.0.1:34938. Username: null; SSL certificate subject DN: unavailable
为什么会出现这种情况?我不是已经将用户名设置为“artemis”了吗?为什么说它是“null”?
您的应用程序能够发送消息这一事实表明它实际上使用了正确的凭据。
代理日志中报告的
AMQ229031
错误毫无疑问与Spring Boot中的AMQ229031
报告的org.springframework.boot.actuate.jms.JmsHealthIndicator
错误相同。我不确定这个 Spring Boot 组件在哪里查找其配置,但它需要使用与您的应用程序使用的相同的凭据。现在它显然没有使用任何凭证,这就是为什么经纪人报告正在接收null
用户名。