Menu Search

csharp.example.helloworld.cs

using System;
using Org.Apache.Qpid.Messaging;

namespace Org.Apache.Qpid.Messaging {
    class Program {
        static void Main(string[] args) {
            String broker = args.Length > 0 ? args[0] : "localhost:5672";
            String address = args.Length > 1 ? args[1] : "amq.topic";

            Connection connection = null;
            try {
                connection = new Connection(broker);
                connection.Open();
                Session session = connection.CreateSession();

                Receiver receiver = session.CreateReceiver(address);
                Sender sender = session.CreateSender(address);

                sender.Send(new Message("Hello world!"));

                Message message = new Message();
                message = receiver.Fetch(DurationConstants.SECOND * 1);
                Console.WriteLine("{0}", message.GetContent());
                session.Acknowledge();

                connection.Close();
            } catch (Exception e) {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
        }
    }
}

Download this file