public static async Task Run()
        {
            Console.WriteLine("Go to http://requestb.in/ and click on \"Create a RequestBin\" to get a test URL");
            Console.WriteLine("Enter testing URL:");
            string endPointUrl = Console.ReadLine();

            IronMqRestClient ironMq = IronSharp.IronMQ.Client.New();

            PushForwardClient pushForwardClient = IronSharp.Extras.PushForward.Client.New(ironMq);

            PushForwardQueueClient pushQueue = await pushForwardClient.PushQueue("PushForward");

            string wrongUrl = endPointUrl + "notexists.wrong";

            await pushQueue.SetErrorQueue("ErrorQ", new Alert
            {
                Direction = AlertDirection.Asc,
                Queue     = "Send Admin Alert",
                Trigger   = 1
            });

            if (!pushQueue.HasSubscriber(wrongUrl))
            {
                await pushQueue.AddSubscriber(new SubscriberItem
                {
                    Url     = wrongUrl,
                    Headers = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/json" }
                    }
                });

                Console.WriteLine("Subscriber added");
                Console.WriteLine(pushQueue.QueueInfo.Inspect());
                Console.ReadLine();
            }

            MessageIdCollection queuedUp = await pushQueue.QueuePushMessage(new
            {
                message = "hello, my name is Push Forward",
                endPointUrl,
                guid = Guid.NewGuid()
            });

            Console.WriteLine(queuedUp.Inspect());

            Console.WriteLine("Message pushed to bad end point");
            Console.ReadLine();

            await pushQueue.ReplaceSubscribers(endPointUrl);

            Console.WriteLine("End point fixed");
            Console.ReadLine();

            MessageIdCollection resentMessages = await pushQueue.ResendFailedMessages();

            Console.WriteLine(resentMessages.Inspect());
        }
示例#2
0
        public static async Task Run()
        {
            // =========================================================
            // Iron.io MQ
            // =========================================================

            IronMqRestClient ironMq = IronSharp.IronMQ.Client.New();

            // Get a Queue object
            QueueClient queue = ironMq.Queue("my_queue");

            QueueInfo info = await queue.Info();

            Console.WriteLine(info.Inspect());

            // Put a message on the queue
            string messageId = await queue.Post("hello world!");

            Console.WriteLine(messageId);

            // Use a webhook to post message from a third party
            Uri webhookUri = queue.WebhookUri();

            Console.WriteLine(webhookUri);

            // Get a message
            QueueMessage msg = await queue.Next();

            Console.WriteLine(msg.Inspect());

            //# Delete the message
            bool deleted = await msg.Delete();

            Console.WriteLine("Deleted = {0}", deleted);

            var payload1 = new
            {
                message = "hello, my name is Iron.io 1"
            };

            var payload2 = new
            {
                message = "hello, my name is Iron.io 2"
            };

            var payload3 = new
            {
                message = "hello, my name is Iron.io 3"
            };

            MessageIdCollection queuedUp = await queue.Post(new[] { payload1, payload2, payload3 });

            Console.WriteLine(queuedUp.Inspect());

            QueueMessage next;

            while (queue.Read(out next))
            {
                Console.WriteLine(next.Inspect());
                Console.WriteLine("Deleted = {0}", await next.Delete());
            }
        }