An IReceiptBehavior that adds a Receipt Header for every outgoing message and wait for the server to send receipt to that message. Create only one instance of this behavior for every destination that you want to use it with.
Inheritance: IReceiptBehavior
Exemple #1
0
        static void Main(string[] args)
        {
            /*
            // Stomp connection
            TcpClient client = new TcpClient();

            client.Connect("localhost", 61613);

            Task.Factory.StartNew(() =>
            {
                var reader = new StreamReader(client.GetStream(), Encoding.ASCII);
                var messageFactory = new StreamMessageFactory(reader);
                while (true)
                {
                    Console.WriteLine(messageFactory.Create());
                }
            });

            var writer = new StreamWriter(client.GetStream(), Encoding.ASCII);
            var messageSerializer = new StreamMessageSerializer(writer);

            messageSerializer.Serialize(new MessageBuilder("CONNECT").Header("accept-version", "1.2").WithoutBody()).Wait();

            messageSerializer.Serialize(new MessageBuilder("SUBSCRIBE").Header("id", 1).Header("destination", "/queue/a").WithoutBody()).Wait();

            for (int i = 0; i < 1000; i++)
            {
                messageSerializer.Serialize(
                new MessageBuilder("SEND").Header("destination", "/queue/a")
                    .Header("receipt", "message-" + i)
                    .Header("inner-id", i)
                    .WithBody(Encoding.UTF8.GetBytes("Hello World"))).Wait();

            }
            */

            StompClient client = new StompClient("localhost", 61613);

            client.Transport.IncommingMessages.GetObservable("ERROR").Subscribe(m => Console.WriteLine("ERROR!" + m));
            var destination = client.GetDestination("/queue/a", client.SubscriptionBehaviors.AutoAcknowledge);
            
            IReceiptBehavior receiptBehavior = new ReceiptBehavior(destination.Destination, client.Transport.IncommingMessages);
            receiptBehavior = NoReceiptBehavior.Default;
            Stopwatch sw = Stopwatch.StartNew();
            //using (var transaction = client.GetTransaction().Result)
            using (destination.IncommingMessages.Subscribe(WriteMessageId))
            {
                //SendMessages(destination, receiptBehavior, transaction).Wait();
                //transaction.Commit();

                Console.WriteLine("Subscribed to messages, Press enter to ack last one");
                Console.ReadLine();

                //lastMessage.Ack().Wait();
                Console.WriteLine("Ackd last message, press enter to end subscription and dispose client");
                Console.ReadLine();
            }


            client.Dispose();
            Console.WriteLine(sw.Elapsed);
            return;

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            /*
             * // Stomp connection
             * TcpClient client = new TcpClient();
             *
             * client.Connect("localhost", 61613);
             *
             * Task.Factory.StartNew(() =>
             * {
             *  var reader = new StreamReader(client.GetStream(), Encoding.ASCII);
             *  var messageFactory = new StreamMessageFactory(reader);
             *  while (true)
             *  {
             *      Console.WriteLine(messageFactory.Create());
             *  }
             * });
             *
             * var writer = new StreamWriter(client.GetStream(), Encoding.ASCII);
             * var messageSerializer = new StreamMessageSerializer(writer);
             *
             * messageSerializer.Serialize(new MessageBuilder("CONNECT").Header("accept-version", "1.2").WithoutBody()).Wait();
             *
             * messageSerializer.Serialize(new MessageBuilder("SUBSCRIBE").Header("id", 1).Header("destination", "/queue/a").WithoutBody()).Wait();
             *
             * for (int i = 0; i < 1000; i++)
             * {
             *  messageSerializer.Serialize(
             *  new MessageBuilder("SEND").Header("destination", "/queue/a")
             *      .Header("receipt", "message-" + i)
             *      .Header("inner-id", i)
             *      .WithBody(Encoding.UTF8.GetBytes("Hello World"))).Wait();
             *
             * }
             */

            StompClient client = new StompClient("localhost", 61613);

            client.Transport.IncommingMessages.GetObservable("ERROR").Subscribe(m => Console.WriteLine("ERROR!" + m));
            var destination = client.GetDestination("/queue/a", client.SubscriptionBehaviors.AutoAcknowledge);

            IReceiptBehavior receiptBehavior = new ReceiptBehavior(destination.Destination, client.Transport.IncommingMessages);

            receiptBehavior = NoReceiptBehavior.Default;
            Stopwatch sw = Stopwatch.StartNew();

            //using (var transaction = client.GetTransaction().Result)
            using (destination.IncommingMessages.Subscribe(WriteMessageId))
            {
                //SendMessages(destination, receiptBehavior, transaction).Wait();
                //transaction.Commit();

                Console.WriteLine("Subscribed to messages, Press enter to ack last one");
                Console.ReadLine();

                //lastMessage.Ack().Wait();
                Console.WriteLine("Ackd last message, press enter to end subscription and dispose client");
                Console.ReadLine();
            }


            client.Dispose();
            Console.WriteLine(sw.Elapsed);
            return;

            Console.ReadLine();
        }