0

c#を使用してstompプロトコルを使用してactiveMQのキューからメッセージを送受信しようとしています。activemqとstompについてはよくわかりません。そのため、段階的に学習できる適切なドキュメントまたはサンプルコードを探しています。

  static void Main(string[] args)
    {
        Apache.NMS.Stomp.ConnectionFactory factory  = new Apache.NMS.Stomp.ConnectionFactory(new Uri("stomp:tcp://localhost:61613"));
        IConnection connection = factory.CreateConnection();
        ISession session = connection.CreateSession();
        IDestination destination = session.GetDestination("/queue/notification");
        IMessageConsumer consumer = session.CreateConsumer(destination);
        connection.Start();
        consumer.Listener += new MessageListener(OnMessage);
        Console.WriteLine("Consumer started, waiting for messages... (Press ENTER to stop.)");
        Console.ReadLine();
        connection.Close();
    }
    private static void OnMessage(IMessage message)
    { 
        try
        { 
            Console.WriteLine("Median-Server (.NET): Message received"); 
            ITextMessage msg = (ITextMessage)message; 
            message.Acknowledge();
            Console.WriteLine(msg.Text);
        } 
        catch (Exception ex)
        { 
            Console.WriteLine(ex.Message);
            Console.WriteLine("---");
            Console.WriteLine(ex.InnerException);
            Console.WriteLine("---"); 
            Console.WriteLine(ex.InnerException.Message);
        }
    }
}

}私はこれを試しました。ストンプ接続を行う正しい方法ですか。

4

1 に答える 1

2

さまざまな言語のSTOMP用のクライアントライブラリがあります。.NET用には、STOMPセマンティクスの周りにJMSタイプのファサードを配置するApache.NMS.Stompライブラリがあります。より技術的になり、STOMPプロトコルが実際に何であるかを知りたい場合は、STOMP仕様は非常に明確で理解しやすいものです。そしてもちろん、ActiveMQ自身のサイトには、STOMPサポートに関するいくつかのドキュメントがあります。一部のWeb検索では、NMS.Stompライブラリを使用してActiveMQと対話するための優れたブログ投稿もすぐに見つかります。

于 2013-01-21T17:36:42.607 に答える