使用用户名/密码验证与 activeMQ 的连接
我有一个应用程序运行正常,可以向 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 代理的很好的示例或提示吗?
I have an application running ok sending messages to activemq. I'm using spring.net and Nmstemplate to connect to broker.
xml configuration file in general is:
<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>
Until everything is working find sending message with NmsTemplate.ConvertAndSend();
The problem is that I want to secure connection using username/password.
I setup credentials in activemq configuration file and now I need to supply this credentials in code but I dont find where !!
I tried with:
<object id="ActiveMqConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<property name="UserName" value="usertest"/>
<property name="Password" value="passwordtest"/>
</object>
But when sending I get "Connection already closed" exception, and the same setting credentials in code.
So, anyone have a good example or hint in how to setup username/password to send message to secured activemq broker?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于没有人回答这个问题,我在 http://forum.springframework.net/showthread.php?9184-authenticate-to-activeMQ-using-Nmstemplate-in-net
Since no-one has answered this, I found this answer on http://forum.springframework.net/showthread.php?9184-authenticate-to-activeMQ-using-Nmstemplate-in-net
尝试以下操作,它会使用
userNam
e & 创建一个连接。password
然后启动它创建session
,然后用于创建一个使用consumer.Receive()
的consumer
从队列中读取单个消息。Try the following, it creates a Connection with
userNam
e &password
then starts it to create assession
which then used to create aconsumer
which usesconsumer.Receive()
to read a single message form the queue.