在连接到 Sonic Broker 时,我喜欢下面的效果很好,
TopicConnectionFactory factory = new progress.message.jclient.TopicConnectionFactory(brokerURL);
TopicConnection connection = factory.createTopicConnection(brokerUserName, brokerPassword);
javax.jms.TopicSession subSession = (TopicSession) connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Topic topic = subSession.createTopic(topicNameToListen);
MessageConsumer subscriber = subSession.createSubscriber(topic);
subscriber.setMessageListener(msgListener);
connection.start();
因此,在使用弹簧靴进行操作时,我做到了,
@Bean
TopicConnectionFactory connectionFactory() throws JMSException {
TopicConnectionFactory factory = new progress.message.jclient.TopicConnectionFactory(brokerURL);
TopicConnection connection = factory.createTopicConnection(brokerUserName, brokerPassword);
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
return factory;
}
@Bean
JmsListenerContainerFactory<?> myJmsContainerFactory(ConnectionFactory connectionFactory) {
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
return factory;
}
@JmsListener(destination = "topic.name.for.receiving.message", containerFactory = "myJmsContainerFactory")
public void messageReceiver(String message) {
LogService.info(this.getClass().getName(), "A Message Received");
LogService.info(this.getClass().getName(), message);
}
但如果我运行这个,我得到Exception,
javax.jms.JMSSecurityException: Inauthentic Client
at progress.message.jimpl.JMSExceptionUtil.createJMSSecurityException(JMSExceptionUtil.java:134)
at progress.message.jimpl.JMSExceptionUtil.createJMSSecurityException(JMSExceptionUtil.java:117)
at progress.message.jimpl.JMSExceptionUtil.createJMSSecurityException(JMSExceptionUtil.java:103)
at progress.message.jimpl.Connection.<init>(Connection.java:836)
at progress.message.jclient.ConnectionFactory.createConnection(ConnectionFactory.java:2110)
at progress.message.jclient.ConnectionFactory.createConnection(ConnectionFactory.java:2083)
注意:我已经多次检查凭据并使用以前的代码运行它,它工作正常。我还添加了sonic_Client.jar, sonic_Crypto.jar and sonic_XMessage.jar. 如果我尝试使用 spring boot,我会收到此错误。
这可能是什么原因?