2012-05-02 6 views
1

SimpleMessageListenerContainerオプションを除くと、コンシューマは一時キュー用に作成されません。私は次のコードhere.なぜ消費者がActiveMQ Temp Queue用に作成されないのですか?

に直面していましたが

     using (IConnection connection = connectionFactory.CreateConnection()) 
        using (ISession session = connection.CreateSession()) 
        { 
         IDestination destination = SessionUtil.GetDestination(session, aQueueName); 
         var replyDestination = session.CreateTemporaryQueue(); 

         // Create a consumer and producer 
         using (IMessageProducer producer = session.CreateProducer(destination)) 
         { 
          // Start the connection so that messages will be processed. 
          connection.Start(); 

          IBytesMessage request = session.CreateBytesMessage(aMsg); 
          request.NMSReplyTo = replyDestination; 

          IMessageConsumer consumer = session.CreateConsumer(replyDestination); 
          consumer.Listener += new MessageListener(this.OnAckRecieved); 

          // Send a message 
          producer.Send(request); 
          ack = this.autoEvent.WaitOne(this.msgConsumeTimeOut, true); 

          consumer.Close(); 
          consumer.Dispose(); 
          ConnectionFactoryUtils.GetTargetSession(session).DeleteDestination(replyDestination); 
         } 
         connection.Close(); 
         session.Close(); 

(でも一時キューが作成されません)...ワーキングコードをFlollowingされていないいくつかの問題のためにSimpleMessageListenerContainerを使用することはありません が働いている:キューがいるようだ - ブタそれは永続的なキューを作成working.butある(NmsDestinationAccessorの使用)上記のコードで永続キューない一時キュー

     using (IConnection connection = connectionFactory.CreateConnection()) 
        using (ISession session = connection.CreateSession()) 
        { 
         IDestination destination = SessionUtil.GetDestination(session, aQueueName); 
         var replyDestination = session.CreateTemporaryQueue(); 

         // Create a consumer and producer 
         using (IMessageProducer producer = session.CreateProducer(destination)) 
         { 
          // Start the connection so that messages will be processed. 
          connection.Start(); 

          IBytesMessage request = session.CreateBytesMessage(aMsg); 
          request.NMSReplyTo = replyDestination; 

          IDestination tempDestination = this.destinationResolver.ResolveDestinationName(session, request.NMSReplyTo.ToString()); 
          IMessageConsumer consumer = session.CreateConsumer(tempDestination); 
          consumer.Listener += new MessageListener(this.OnAckRecieved); 

          // Send a message 
          producer.Send(request); 
          ack = this.autoEvent.WaitOne(this.msgConsumeTimeOut, true); 

          consumer.Close(); 
          consumer.Dispose(); 
          ConnectionFactoryUtils.GetTargetSession(session).DeleteDestination(tempDestination); 
         } 
         connection.Close(); 
         session.Close(); 

です。だから、私は一時的なキューの返信先を直接使用して、それは動作していません。

+0

「作成されていない」とはどういう意味ですか?CreateConsumer()は例外をスローするか、nullを返しますか? –

+0

エラーはまったくありません。私がwebconsoleに見ると、たとえtempキューも2番目のコード用に作成されていません.3番目のコードでは、コンシューマだけが作成されません。 –

+0

NMSプロジェクトの実例を示すNUnitテストの例を追加しました。 –

答えて

0
  1. C#を使用するのではなく、Javaでコードを記述してください。これはActiveMQのベストスイートです。 here for examples using temp queue in java.
  2. を読み、その後、JARファイルにそれをコンパイルして、あなたが
  3. hereが、それはこの協力をお願いし説明したようIKVM.NETを経由してあなたのC#コードでそれをインポートすることができます。

注意:異なるセッションでテモゾルキューを使用することはできません。

0

メソッドから直接ActiveMQTempQueueオブジェクトを作成すると、ToStringメソッドは、一致する宛先を作成できる値を返すことが保証されていない可能性があります。送信者が一時的な送信先を指定したのか、通常の送信先を指定したのかがわからないので、悪いコーディングも同様です。正しいことは、単にNSMReplyTo宛先をそのまま使用して、セッションのコンシューマー作成メソッドを使用して新しいコンシューマーを作成することです。

ここには、Apache.NMS.StompとApache.NMS.ActiveMQで動作するNMSプロジェクトの簡単なリクエスト応答テストケースがあります。

namespace Apache.NMS.Test 
{ 
[TestFixture] 
public class RequestResponseTest : NMSTestSupport 
{ 
    protected static string DESTINATION_NAME = "RequestDestination"; 

    [Test] 
    [Category("RequestResponse")]  
    public void TestRequestResponseMessaging() 
    { 
     using(IConnection connection = CreateConnection()) 
     { 
      connection.Start(); 
      using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 
      { 
       IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); 
       ITemporaryQueue replyTo = session.CreateTemporaryQueue(); 

       using(IMessageConsumer consumer = session.CreateConsumer(destination)) 
       using(IMessageProducer producer = session.CreateProducer(destination)) 
       { 
        IMessage request = session.CreateMessage(); 

        request.NMSReplyTo = replyTo; 

        producer.Send(request); 

        request = consumer.Receive(TimeSpan.FromMilliseconds(3000)); 
        Assert.IsNotNull(request); 
        Assert.IsNotNull(request.NMSReplyTo); 

        using(IMessageProducer responder = session.CreateProducer(request.NMSReplyTo)) 
        { 
         IMessage response = session.CreateTextMessage("RESPONSE");       
         responder.Send(response); 
        }      
       } 

       using(IMessageConsumer consumer = session.CreateConsumer(replyTo)) 
       { 
        ITextMessage response = consumer.Receive(TimeSpan.FromMilliseconds(3000)) as ITextMessage; 
        Assert.IsNotNull(response); 
        Assert.AreEqual("RESPONSE", response.Text); 
       } 
      } 
     } 
    } 
} 
+0

完全なコードがない場合は、3番目のコードでコンシューマーが作成され、使用ブロックの直後にコンシューマーが廃棄され、ブローカーからの購読を取り消すことができます。 –

+0

私との違い:1)connection.Start()はconsumerを作成する前に置かれます.2)connection.createSessionはconnection.Start()の前に置かれます。それは理由だろうか? –

+0

唯一のことconnection.Startは、メッセージのコンシューマーへのディスパッチを促進することです。物事がうまくいかない場合は、NUnitのテストケースを作成し、Apacheの新しいJiraの問題にアタッチしてください。 –

0

一時的なキューは、それを作成した接続が存在する間のみ存在します。あなたのサンプルコードでは、接続を開始する前にそれを作成しているので、アクティブな接続がないので、静かにエラーを出力すると思います。

+0

startを呼び出す前にそれらを作成することは合法ですが、これはstartメソッドの意図です。通常、startを呼び出す前に、すべての送り先、プロデューサ、コンシューマを作成します。 –

+0

さて、私は一時的な待ち行列を使用していない、彼は一時的な待ち行列が作成されていないと言ったので、私はちょうどそれが問題かもしれないと推測した。あなたのテストケースでは、接続が存在した後に作成され、それが主要な違いかもしれないと考えられています。 – Thymine

関連する問題