2011-08-10 75 views
2

私はokを実行しているアプリケーションをactivemqに送信しています。私はspring.netとNmstemplateを使ってブローカーに接続しています。一般的に XML設定ファイルは次のとおりです。ユーザ名/パスワードでactiveMQへの接続を認証します。

<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ブローカーにメッセージを送信するためのユーザー名/パスワードの設定方法の良い例やヒントを持っていますか?

答えて

1

誰がこれを答えなかったので、私はあなたがもう少し説明できhttp://forum.springframework.net/showthread.php?9184-authenticate-to-activeMQ-using-Nmstemplate-in-net

this.ConnectionFactory.UserName = this.Username; 
this.ConnectionFactory.Password = this.Password; 

this.ConnectionFactory.BrokerUri = new System.Uri(this.Uri); 

using (IConnection conn = this.ConnectionFactory.CreateConnection()) 
{ 
using (ISession session = conn.CreateSession()) 
{ 
    IObjectMessage objMessage = session.CreateObjectMessage(message); 
    using (IMessageProducer producer = session.CreateProducer()) 
      { 
        NmsDestinationAccessor destinationResolver = new NmsDestinationAccessor(); 
        IDestination destination = destinationResolver.ResolveDestinationName(session, this.Queue); 
        producer.Send(destination, objMessage); 
      } 
    } 
} 
+0

にこの答えを見つけましたか? –

関連する問題