我有一个运行正常的应用程序向 activemq 发送消息。我正在使用 spring.net 和 Nmstemplate 连接到代理。xml配置文件一般是:
<object id="ActiveMqConnectionFactory"
type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
</object>
<object id="ConnectionFactory"
type="Spring.Messaging.Nms.Connections.CachingConnectionFactory, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ActiveMqConnectionFactory"/>
<property name="SessionCacheSize" value="10"/>
</object>
<object id="NmsTemplate"
type="Spring.Messaging.Nms.Core.NmsTemplate, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ConnectionFactory"/>
<property name="MessageConverter" ref="SimpleMessageConverter"/>
</object>
<object id="SimpleMessageConverter"
type="Spring.Messaging.Nms.Support.Converter.SimpleMessageConverter, Spring.Messaging.Nms">
</object>
直到一切正常,使用 NmsTemplate.ConvertAndSend(); 找到发送消息 问题是我想使用用户名/密码来保护连接。我在 activemq 配置文件中设置了凭据,现在我需要在代码中提供此凭据,但我找不到在哪里!我试过:
<object id="ActiveMqConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<property name="UserName" value="usertest"/>
<property name="Password" value="passwordtest"/>
</object>
但是在发送时,我得到“连接已关闭”异常,并且在代码中设置了相同的凭据。
那么,任何人都有一个很好的例子或提示如何设置用户名/密码以将消息发送到安全的 activemq 代理?