private static void TestGettingListQueue(IronMqRestClient ironMq) { var names = new[] { "a", "b", "c", "d", "e" }; foreach (var name in names) { var queue = ironMq.Queue(name); queue.Post("1"); } var queues = ironMq.Queues(); foreach (var queueInfo in queues) { Console.WriteLine(queueInfo.Name); } var pagedQueues = ironMq.Queues(new MqPagingFilter { PerPage = 4, Previous = "c" }); foreach (var queueInfo in pagedQueues) { Console.WriteLine(queueInfo.Name); } }
public List <string> ListarHotelesNoValidados() { IronMqRestClient ironMq = Client.New(new IronClientConfig { ProjectId = "5bf768af967e0f000910fed3", Token = "y7TU7c3D3IUXtwrcJJFH", Host = "mq-aws-eu-west-1-1.iron.io", ApiVersion = 3, Scheme = Uri.UriSchemeHttp }); QueueClient queueHotel = ironMq.Queue("Hotel"); bool finished = false; var hotelIds = new List <string>(); while (!finished) { var messageHotel = queueHotel.Reserve(1, new TimeSpan(0, 0, 5)); if (messageHotel != null && messageHotel.Messages.Any()) { hotelIds.Add(messageHotel.Messages[0].Body.ToString()); } else { finished = true; } } return(hotelIds.Select(x => x).Distinct().ToList()); }
private static void TestPosting(IronMqRestClient ironMq) { QueueClient q = ironMq.Queue("my_queue"); string messageId = q.Post("some data"); Console.WriteLine("Posted message with id {0}", messageId); }
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()); }
private static void TestUpdatingTheQueue(IronMqRestClient ironMq) { var q = ironMq.Queue("my_msg_updateable_queue"); q.Post("1"); var info = q.Update(new QueueInfo { PushType = PushType.Pull, MessageTimeout = 58, MessageExpiration = 603333 }); }
private static void ClearMessagesHotel() { IronMqRestClient ironMq = Client.New(new IronClientConfig { ProjectId = "5bf768af967e0f000910fed3", Token = "y7TU7c3D3IUXtwrcJJFH", Host = "mq-aws-eu-west-1-1.iron.io", ApiVersion = 3, Scheme = Uri.UriSchemeHttp }); QueueClient queueHabitacion = ironMq.Queue("Hotel"); queueHabitacion.Clear(); }
private static void TestDeletingQueue(IronMqRestClient ironMq) { var q = ironMq.Queue("my_deletable_queue"); q.Post("1"); var result = q.Delete(); var info = q.Info(); Console.WriteLine("Should be null: {0}", info == null); }
private static void TestClearingQueue(IronMqRestClient ironMq) { var q = ironMq.Queue("my_clearable_queue"); q.Post("1"); q.Post("2"); q.Post("3"); Console.WriteLine(" >>> {0}", q.Info().Size); q.Clear(); Console.WriteLine(" >>> {0}", q.Info().Size); }
private static void TestGettingMessageById(IronMqRestClient ironMq) { var q = ironMq.Queue("my_test_queue"); q.Clear(); var text = "some text " + DateTime.Now.Millisecond; var id = q.Post(text); var message = q.Get(id); Console.WriteLine("Text of mesage should be eq to \"{0}\": {1}", text, message.Body); }
//Will move to services project maybe public ChatServices() { this.ironMq = Client.New( new IronClientConfig { ProjectId = "56420b6f9195a800080000b6", Token = "ANgrGMpOtkzSxbTIlWbk", Host = "mq-aws-eu-west-1-1.iron.io", ApiVersion = 3 }); this.currentQueue = this.ironMq.Queue("Global"); }
private static void TestPeekingMessage(IronMqRestClient ironMq) { var q = ironMq.Queue("my_peekable_queue"); q.Clear(); q.Post("1"); q.Post("2"); var m1 = q.PeekNext(); var m2 = q.PeekNext(); Console.WriteLine("Ids of messages should be equal: {0} == {1}", m1.Id, m2.Id); }
private static void TestDeletingMessage(IronMqRestClient ironMq) { var q = ironMq.Queue("my_msg_deletable_queue"); q.Clear(); q.Post("1"); q.Post("2"); var message = q.PeekNext(); message.Delete(); Console.WriteLine("Size of Q should be equal to one: {0}", q.Info().Size); }
private static void TestTouchingTwice(IronMqRestClient ironMq) { var q = ironMq.Queue("my_touchable_queue"); q.Post("1"); var msg = q.Reserve(); Console.WriteLine(msg.ReservationId); Thread.Sleep(2000); msg.Touch(); Thread.Sleep(1000); msg.Touch(); }
private static void TestReleasing(IronMqRestClient ironMq) { var q = ironMq.Queue("my_releasable_queue"); q.Post("1"); q.Post("2"); var msg = q.Reserve(); Console.WriteLine(msg.ReservationId); var result = msg.Release(); Console.WriteLine(" >>> {0}Released", result ? "" : "Not "); }
public static void AgregarCola(string Cola, string Mensaje) { IronMqRestClient iromMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = ParametrosConfiguracionBE.ColasProjectId, Token = ParametrosConfiguracionBE.ColasToken, Host = ParametrosConfiguracionBE.ColasHost, Scheme = "http", Port = 80 }); var queue = iromMq.Queue(Cola); queue.Post(Mensaje); }
private static void TestTouchRelease(IronMqRestClient ironMq) { var q = ironMq.Queue("my_toasdf_queue"); q.Post("1"); var msg1 = q.Reserve(); msg1.Release(); Thread.Sleep(100); var msg2 = q.Reserve(); msg2.Release(); Console.WriteLine("{0} {1}", msg1.Id, msg1.ReservationId); Console.WriteLine("{0} {1}", msg2.Id, msg2.ReservationId); }
private static void TestReservation(IronMqRestClient ironMq) { var q = ironMq.Queue("my_reservable_queue"); q.Post("1"); q.Post("2"); q.Post("3"); var msg = q.Reserve(); var messages = q.Reserve(wait: 12); foreach (var message in messages.Messages) { Console.WriteLine(message.ReservationId); } Console.WriteLine(msg.ReservationId); }
public static void LimpiearCola(string Cola) { IronMqRestClient iromMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = ParametrosConfiguracionBE.ColasProjectId, Token = ParametrosConfiguracionBE.ColasToken, Host = ParametrosConfiguracionBE.ColasHost, Scheme = "http", Port = 80 }); var queue = iromMq.Queue(Cola); queue.Clear(); queue.Delete(); }
private static void TestDeletingMessages(IronMqRestClient ironMq) { var q = ironMq.Queue("my_msg_deletable_queue"); q.Clear(); q.Post("1"); q.Post("2"); q.Post("3"); var ms = q.Reserve(3, 0); q.Delete(ms); // or //q.Delete(ms.Messages.ConvertAll(m => m.Id)); Console.WriteLine("Size of Q should be eq to zero: {0}", q.Info().Size); }
private static void CrearCola3MensajeHotel() { IronMqRestClient ironMq = Client.New(new IronClientConfig { ProjectId = "5bf768af967e0f000910fed3", Token = "y7TU7c3D3IUXtwrcJJFH", Host = "mq-aws-eu-west-1-1.iron.io", ApiVersion = 3, Scheme = Uri.UriSchemeHttp }); QueueClient queueHabitacion = ironMq.Queue("Hotel"); var codigoHotel1 = "HT00000001"; queueHabitacion.Post(codigoHotel1); var codigoHotel2 = "HT00000002"; queueHabitacion.Post(codigoHotel2); var codigoHotel3 = "HT00000003"; queueHabitacion.Post(codigoHotel3); }
public void Init() { // Put your ".iron.json" file to home directory, eg. C:\Users\YourUsername ironMq = Client.New(); queue = ironMq.Queue(GetQueueName()); queue.Clear(); // Or config the client here: // ironMq = Client.New(new IronClientConfig // { // ProjectId = "xxxxxxxxxxxxxxxxxxxxxxxx", // Token = "yyyyyyyyyyyyyyyyyyyy", // Host = "host-of-ironmq.com", // ApiVersion = 3, // Port = 80, // Scheme = Uri.UriSchemeHttp // }); }
private static void TestGettingSubscribersInfo(IronMqRestClient ironMq) { var q = ironMq.Queue("my_push_queue"); string url = "http://myURL"; var subscribes = new List <Subscriber> { new Subscriber() { Url = url } }; q.Update(new QueueInfo { PushType = PushType.Multicast, PushInfo = new PushInfo { Subscribers = subscribes } }); Console.WriteLine("Amount of subscribers should be 1: {0}", q.Info().PushInfo.Subscribers.Count); Console.WriteLine("The URL of subscriber should be {0}: {1}", url, q.Info().PushInfo.Subscribers[0].Url); }
public static int ObtenerCola(string Cola) { IronMqRestClient iromMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = ParametrosConfiguracionBE.ColasProjectId, Token = ParametrosConfiguracionBE.ColasToken, Host = ParametrosConfiguracionBE.ColasHost, Scheme = "http", Port = 80 }); var queue = iromMq.Queue(Cola); QueueInfo info = queue.Info(); //MessageCollection mensajes = queue.Reserve(info.Size); return((int)info.Size); }
public static void Main() { IronMqRestClient client = Client.New(IronMqConstants.ProjectId, IronMqConstants.Token); QueueClient queue = client.Queue(IronMqConstants.QueueName); Console.WriteLine("Listening for new messages from IronMQ server:"); while (true) { var msg = queue.Next(); if (msg.Result != null) { Console.WriteLine(msg.Result.Body); Console.WriteLine(); queue.Delete(); } Thread.Sleep(100); } }
private static void ReservedUntilTest(IronMqRestClient ironMq) { var q = ironMq.Queue("my_reserved_until_queue"); q.Clear(); q.Post("1"); var msg = q.Reserve(); DateTime t1 = DateTime.Now; QueueMessage msg2 = null; while (msg2 == null) { Thread.Sleep(1000); msg2 = q.Reserve(); } DateTime t2 = DateTime.Now; Console.WriteLine("Ids: {0} {1}", msg.Id, msg2.Id); Console.WriteLine("Time: {0}", t2 - t1); }
public static PushForwardClient @New(IronMqRestClient ironMq) { return(new PushForwardClient(ironMq)); }
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()); } }
private static void Main(string[] args) { LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(); // ========================================================= // Iron.io MQ // ========================================================= //IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(); // For beta testing IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = "53a3b3bd5e8edd1245000005", Token = "O7KrMTwmw997iq0KzL7v", Host = "192.168.1.155", ApiVersion = 3, Port = 8080, Scheme = Uri.UriSchemeHttp }); // Simple actions // Post message to a queue TestPosting(ironMq); // Post message to a queue and reserve it TestReservation(ironMq); // Post message, reserve it and delete TestDeletingReservedMessage(ironMq); // Actions on queue // Update queue info TestUpdatingTheQueue(ironMq); // Clear all messages of queue TestClearingQueue(ironMq); // Delete queue and its messages TestDeletingQueue(ironMq); // Get list of all queus inside project TestGettingListQueue(ironMq); // Actions on messages //TestPosting(ironMq); //TestReservation(ironMq); //TestDeletingReservedMessage(ironMq); // Get message by id without reservation TestGettingMessageById(ironMq); // Get message without reserving it TestPeekingMessage(ironMq); // Delete unreserved message TestDeletingMessage(ironMq); // Touch message to prolongate reservation TestTouching(ironMq); // Touch message to prolongate reservation TestTouchingTwice(ironMq); // Release reserved message TestReleasing(ironMq); // Delete a bunch of messages TestDeletingMessages(ironMq); // Get subscriber's URL TestGettingSubscribersInfo(ironMq); // ========================================================= // Iron.io Worker // ========================================================= Console.WriteLine("Be sure to create a 'Test' worker before running this sample"); Console.WriteLine("Press ANY key to continue"); Console.Read(); IronWorkerRestClient workerClient = IronSharp.IronWorker.Client.New(); string taskId = workerClient.Tasks.Create("Test", new { Key = "Value" }); Console.WriteLine("TaskID: {0}", taskId); TaskInfoCollection taskInfoCollection = workerClient.Tasks.List("Test"); foreach (TaskInfo task in taskInfoCollection.Tasks) { Console.WriteLine(task.Inspect()); } ScheduleOptions options = ScheduleBuilder.Build(). Delay(TimeSpan.FromMinutes(1)). WithFrequency(TimeSpan.FromHours(1)). RunFor(TimeSpan.FromHours(3)). WithPriority(TaskPriority.Default); var payload = new { a = "b", c = new[] { 1, 2, 3 } }; ScheduleIdCollection schedule = workerClient.Schedules.Create("Test", payload, options); Console.WriteLine(schedule.Inspect()); workerClient.Schedules.Cancel(schedule.Schedules.First().Id); // ========================================================= // Iron.io Cache // ========================================================= IronCacheRestClient ironCacheClient = IronSharp.IronCache.Client.New(); // Get a Cache object CacheClient cache = ironCacheClient.Cache("my_cache"); // Put value to cache by key cache.Put("number_item", 42); // Get value from cache by key Console.WriteLine(cache.Get("number_item").Value); // Get value from cache by key Console.WriteLine(cache.Get <int>("number_item")); // Numbers can be incremented cache.Increment("number_item", 10); // Immediately delete an item cache.Delete("number_item"); cache.Put("complex_item", new { greeting = "Hello", target = "world" }); // Get value from cache by key Console.WriteLine(cache.Get("complex_item").Value); cache.Delete("complex_item"); Console.WriteLine("============= Done =============="); Console.Read(); }
public PushForwardClient(IronMqRestClient ironMq) { _ironMq = ironMq; }
private static void Main(string[] args) { LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(); IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = "5bf768af967e0f000910fed3", Token = "y7TU7c3D3IUXtwrcJJFH", Host = "mq-aws-eu-west-1-1.iron.io", ApiVersion = 3, Scheme = Uri.UriSchemeHttp }); QueueClient queueHabitacion = ironMq.Queue("Habitacion"); var codigoHabitacion = "HBT0000007"; string messageId1 = queueHabitacion.Post(codigoHabitacion); Console.WriteLine("Mensaje enviado: {0}", codigoHabitacion); QueueClient queueHotel = ironMq.Queue("Hotel"); var codigoHotel = "HT00000002"; string messageId2 = queueHotel.Post(codigoHotel); Console.WriteLine("Mensaje enviado: {0}", codigoHabitacion); //QueueMessage messageHabitacion = queueHabitacion.Reserve(); //Console.WriteLine("Respuesta: " + messageHabitacion.Body); //QueueMessage messageHotel = queueHotel.Reserve(); //Console.WriteLine("Respuesta: " + messageHotel.Body); //Console.WriteLine(message.ReservationId); //bool finished = false; //var hotelIds = new List<string>(); //while (!finished) //{ // messageHotel = queueHotel.Reserve(); // if (messageHotel != null) // hotelIds.Add(messageHotel.Body); // else // finished = true; //} LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(); // ========================================================= // Iron.io MQ // ========================================================= //IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(); // For beta testing //IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = "53a3b3bd5e8edd1245000005", Token = "O7KrMTwmw997iq0KzL7v", Host = "192.168.1.155", ApiVersion = 3, Port = 8080, Scheme = Uri.UriSchemeHttp }); // Simple actions // Post message to a queue TestPosting(ironMq); // Post message to a queue and reserve it TestReservation(ironMq); // Post message, reserve it and delete TestDeletingReservedMessage(ironMq); // Actions on queue // Update queue info TestUpdatingTheQueue(ironMq); // Clear all messages of queue TestClearingQueue(ironMq); // Delete queue and its messages TestDeletingQueue(ironMq); // Get list of all queus inside project TestGettingListQueue(ironMq); // Actions on messages //TestPosting(ironMq); //TestReservation(ironMq); //TestDeletingReservedMessage(ironMq); // Get message by id without reservation TestGettingMessageById(ironMq); // Get message without reserving it TestPeekingMessage(ironMq); // Delete unreserved message TestDeletingMessage(ironMq); // Touch message to prolongate reservation TestTouching(ironMq); // Touch message to prolongate reservation TestTouchingTwice(ironMq); // Release reserved message TestReleasing(ironMq); // Delete a bunch of messages TestDeletingMessages(ironMq); // Get subscriber's URL TestGettingSubscribersInfo(ironMq); // ========================================================= // Iron.io Worker // ========================================================= Console.WriteLine("Be sure to create a 'Test' worker before running this sample"); Console.WriteLine("Press ANY key to continue"); Console.Read(); IronWorkerRestClient workerClient = IronSharp.IronWorker.Client.New(); string taskId = workerClient.Tasks.Create("Test", new { Key = "Value" }); Console.WriteLine("TaskID: {0}", taskId); TaskInfoCollection taskInfoCollection = workerClient.Tasks.List("Test"); foreach (TaskInfo task in taskInfoCollection.Tasks) { Console.WriteLine(task.Inspect()); } ScheduleOptions options = ScheduleBuilder.Build(). Delay(TimeSpan.FromMinutes(1)). WithFrequency(TimeSpan.FromHours(1)). RunFor(TimeSpan.FromHours(3)). WithPriority(TaskPriority.Default); var payload = new { a = "b", c = new[] { 1, 2, 3 } }; ScheduleIdCollection schedule = workerClient.Schedules.Create("Test", payload, options); Console.WriteLine(schedule.Inspect()); workerClient.Schedules.Cancel(schedule.Schedules.First().Id); // ========================================================= // Iron.io Cache // ========================================================= IronCacheRestClient ironCacheClient = IronSharp.IronCache.Client.New(); // Get a Cache object CacheClient cache = ironCacheClient.Cache("my_cache"); // Put value to cache by key cache.Put("number_item", 42); // Get value from cache by key Console.WriteLine(cache.Get("number_item").Value); // Get value from cache by key Console.WriteLine(cache.Get <int>("number_item")); // Numbers can be incremented cache.Increment("number_item", 10); // Immediately delete an item cache.Delete("number_item"); cache.Put("complex_item", new { greeting = "Hello", target = "world" }); // Get value from cache by key Console.WriteLine(cache.Get("complex_item").Value); cache.Delete("complex_item"); Console.WriteLine("============= Done =============="); Console.Read(); }
private Notificator() { client = Client.New(GlobalConstants.NotificationProductId, GlobalConstants.NotificationToken); }