public IActionResult Fetch([FromBody] FetchMessageModel model) { try { var queue = _queueManager.CreateQueue(model.QueueUri); var countRetrieved = 0; try { for (var i = 0; i < model.Count; i++) { var receivedMessage = queue.GetMessage(); if (receivedMessage != null) { countRetrieved++; TransportMessage transportMessage; try { transportMessage = GetTransportMessage(receivedMessage.Stream); } catch (Exception ex) { _log.Error(ex.AllMessages()); return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } _inspectionQueue.Enqueue(model.QueueUri, transportMessage, receivedMessage.Stream); queue.Acknowledge(receivedMessage.AcknowledgementToken); } else { break; } } } finally { queue.AttemptDispose(); } return(Ok(new { Data = new { CountRetrieved = countRetrieved } })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
// CreateQueue // The IQueueManager interface can accept a news expression to filter the type of news based on a JSON interface that // contains complicated expressions. To simplify the specification of an expresion, RDP offers a news Analyze endpoint // that will take a familar desktop news expression and turn it into a JSON representation required by the queue manager. private static IQueueNode CreateQueue(IQueueManager manager, string newsExpression) { // Analyze the following news query string var analyze = Analyze.Definition(newsExpression).GetData(); if (analyze.IsSuccess) { return(manager.CreateQueue(analyze.Data)); } else { Console.WriteLine($"Issues analyzing newsExpression [{newsExpression}\n{analyze.HttpStatus}\nCreating queue with no criteria."); return(manager.CreateQueue()); } }
public void Initialize() { queueManager = new QueueManager(); var firstWashingQueue = queueManager.CreateQueue(Int32.Parse(configuration["FirstWashingBayQueueSize"]), Enums.Enum.QueueType.Washing); var secondWashingQueue = queueManager.CreateQueue(Int32.Parse(configuration["SecondWashingBayQueueSize"]), Enums.Enum.QueueType.Washing); var thirdWashingQueue = queueManager.CreateQueue(Int32.Parse(configuration["ThirdWashingBayQueueSize"]), Enums.Enum.QueueType.Washing); var dryingQueue = queueManager.CreateQueue(Int32.Parse(configuration["DryingBayQueueSize"]), Enums.Enum.QueueType.Drying); bayManager = new BayManager(queueManager); bayManager.Processed += BayManager_Processed; bayManager.ProcessTime += BayManager_ProcessTime; bayManager.CreateBay(firstWashingQueue, Enums.Enum.BayType.Washing, Int32.Parse(configuration["FirstWashingBayProcessingSecond"])); bayManager.CreateBay(secondWashingQueue, Enums.Enum.BayType.Washing, Int32.Parse(configuration["SecondWashingBayProcessingSecond"])); bayManager.CreateBay(thirdWashingQueue, Enums.Enum.BayType.Washing, Int32.Parse(configuration["ThirdWashingBayProcessingSecond"])); bayManager.CreateBay(dryingQueue, Enums.Enum.BayType.Drying, Int32.Parse(configuration["FirstDryingBayProcessingSecond"])); bayManager.CreateBay(dryingQueue, Enums.Enum.BayType.Drying, Int32.Parse(configuration["SecondDryingBayProcessingSecond"])); }
public void Execute(OnConfigureQueues pipelineEvent) { if (_configuration.HasControlInbox) { _configuration.ControlInbox.WorkQueue = _configuration.ControlInbox.WorkQueue ?? _queueManager.CreateQueue( _configuration.ControlInbox.WorkQueueUri); _configuration.ControlInbox.ErrorQueue = _configuration.ControlInbox.ErrorQueue ?? _queueManager.CreateQueue( _configuration.ControlInbox.ErrorQueueUri); } if (_configuration.HasInbox) { _configuration.Inbox.WorkQueue = _configuration.Inbox.WorkQueue ?? _queueManager.CreateQueue(_configuration.Inbox.WorkQueueUri); _configuration.Inbox.DeferredQueue = _configuration.Inbox.DeferredQueue ?? ( string.IsNullOrEmpty(_configuration.Inbox.DeferredQueueUri) ? null : _queueManager .CreateQueue(_configuration.Inbox.DeferredQueueUri)); _configuration.Inbox.ErrorQueue = _configuration.Inbox.ErrorQueue ?? _queueManager.CreateQueue(_configuration.Inbox.ErrorQueueUri); } if (_configuration.HasOutbox) { _configuration.Outbox.WorkQueue = _configuration.Outbox.WorkQueue ?? _queueManager.CreateQueue(_configuration.Outbox.WorkQueueUri); _configuration.Outbox.ErrorQueue = _configuration.Outbox.ErrorQueue ?? _queueManager.CreateQueue(_configuration.Outbox.ErrorQueueUri); } if (_configuration.IsWorker) { _configuration.Worker.DistributorControlInboxWorkQueue = _configuration.Worker.DistributorControlInboxWorkQueue ?? _queueManager.CreateQueue(_configuration.Worker.DistributorControlInboxWorkQueueUri); } }
static void Main(string[] _) { const string researchEndpoint = "https://api.refinitiv.com/message-services/v1/research/subscriptions"; try { using (ISession session = Configuration.Sessions.GetSession()) { if (session.Open() == Session.State.Opened) { // Create our Research definition var definition = Queue.Definition(researchEndpoint); // Create a QueueManager to actively manage our queues IQueueManager manager = definition.CreateQueueManager().OnError((err, qm) => Console.WriteLine(err)); // First, check to see if we have any research queues active in the cloud... var queues = manager.GetAllQueues(); // Prepare Research criteria if we plan to create a new AWS queue - we must supply a research ID. JObject criteria = new JObject() { ["transport"] = new JObject() { ["transportType"] = "AWS-SQS" }, ["payloadVersion"] = "2.0", ["userID"] = Configuration.Credentials.ResearchID }; // If no existing queue exists, create one. IQueueNode queue = (queues.Count > 0 ? queues[0] : manager.CreateQueue(criteria)); if (queue != null) { Console.WriteLine($"{Environment.NewLine}{(queues.Count > 0 ? "Using existing" : "Created a new")} queue..."); // Subscribe to the queue. // Note: The subscriber interface has 2 mechanisms to retrieve data from the queue. The first mechanism is to selectively // poll the queue for new messages. The second mechanism is to define a callback/lambda expression and notify the // the subscriber to poll for messages as they come in - this mechansim provides a near realtime result. // // The following example demonstrates the first mechanism. var subscriber = definition.CreateAWSSubscriber(queue); // Poll the queue until we hit any key on the keyboard. // Each poll will timeout after 2 seconds if not messages arrive. Console.WriteLine("Attempt to retrieve research messages. Hit any key to interrupt fetching..."); while (!Console.KeyAvailable) { subscriber.GetNextMessage(2, (research, s) => DisplayResearch(research)); } Console.ReadKey(); // Prompt the user to delete the queue Console.Write("\nDelete the queue (Y/N) [N]: "); var delete = Console.ReadLine(); if (delete?.ToUpper() == "Y") { if (manager.DeleteQueue(queue)) { Console.WriteLine("Successfully deleted queue."); } else { Console.WriteLine($"Issues deleting queue."); } } } } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main(string[] args) { try { // Create the platform session. ISession session = GlobalSettings.Sessions.GetSession(); // Open the session session.Open(); // ******************************************************************************************** // Headline Alert Endpoint URL. // ******************************************************************************************** const string alertHeadlinesEndpoint = "https://api.refinitiv.com/alerts/v1/news-headlines-subscriptions"; // Determine if we are using an existing queue or creating one. The QueueManager will assist us here. IQueueManager manager = DeliveryFactory.CreateQueueManager(new QueueManager.Params().Session(session) .Endpoint(alertHeadlinesEndpoint) .OnError((qm, err) => Console.WriteLine(err))); // First, check to see if we have any news headline queues active in the cloud, if not, create one. List <IQueue> queues = manager.GetAllQueues(); // Determine if we retrieved anything...create one if not. IQueue queue = (queues?.Count > 0 ? queues[0] : manager.CreateQueue()); // Ensure our queue is created if (queue != null) { Console.WriteLine($"{Environment.NewLine}{(queues.Count > 0 ? "Using existing" : "Created a new")} queue..."); // Start polling for news headline messages from the queue // A QueueSubscriber provides the mechanisms to poll the queue and capture each headline alert via lambda expressions IQueueSubscriber subscriber = DeliveryFactory.CreateQueueSubscriber( new AWSQueueSubscriber.Params().Queue(queue) .WithMessagePollingInterval(1) .OnResponse((s, response) => { if (response.IsSuccess) { DisplayHeadline(response.Data.Raw); } else { Console.WriteLine(response.Status); } })); // Open the subscriber to begin polling for messages subscriber.StartPolling(); Console.WriteLine("Polling for messages from the queue...hit any key to stop polling"); // Hit any key to stop... Console.ReadKey(); // Close the subscription - stops polling for messages subscriber.StopPolling(); Console.WriteLine($"{Environment.NewLine}Stopped polling for messages from the queue."); // Prompt the user to delete the queue Console.Write("Delete the queue (Y/N) [N]: "); var delete = Console.ReadLine(); if (delete?.ToUpper() == "Y") { if (manager.DeleteQueue(queue)) { Console.WriteLine("Successfully deleted queue."); } else { Console.WriteLine($"Issues deleting queue {manager.Error}"); } } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n***************"); } }
static void Main(string[] _) { const string newsStoriesEndpoint = "https://api.refinitiv.com/message-services/v1/news-stories/subscriptions"; try { using (ISession session = Configuration.Sessions.GetSession()) { // Open the session session.Open(); // Create our stories definition var definition = Queue.Definition(newsStoriesEndpoint); // Create a QueueManager to actively manage our queues IQueueManager manager = definition.CreateQueueManager().OnError((err, qm) => Console.WriteLine(err)); // First, check to see if we have any news headline queues active in the cloud... var queues = manager.GetAllQueues(); // If no existing queue exists, create one. IQueueNode queue = (queues.Count > 0 ? queues[0] : manager.CreateQueue()); // Ensure our queue is created if (queue != null) { Console.WriteLine($"{Environment.NewLine}{(queues.Count > 0 ? "Using existing" : "Created a new")} queue. Waiting for stories..."); // Subscribe to the queue. // Note: The subscriber interface has 2 mechanisms to retrieve data from the queue. The first mechanism is to selectively // poll the queue for new messages. The second mechanism is to define a callback/lambda expression and notify the // the subscriber to poll for messages as they come in - this mechansim provides a near realtime result. // // The following example demonstrates the second mechanism. IQueueSubscriber subscriber = definition.CreateAWSSubscriber(queue); // Open the subscriber to begin polling for messages. Use Async() as this method is a long running task. var task = subscriber.StartPollingAsync((story, s) => DisplayStory(story)); Console.ReadKey(); // Close the subscription - stops polling for messages subscriber.StopPolling(); task.GetAwaiter().GetResult(); Console.WriteLine("Stopped polling for messages from the queue."); // Prompt the user to delete the queue Console.Write("Delete the queue (Y/N) [N]: "); var delete = Console.ReadLine(); if (delete?.ToUpper() == "Y") { if (manager.DeleteQueue(queue)) { Console.WriteLine("Successfully deleted queue."); } else { Console.WriteLine($"Issues deleting queue."); } } } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main(string[] _) { const string researchEndpoint = "https://api.refinitiv.com/message-services/v1/research/subscriptions"; try { using (ISession session = Configuration.Sessions.GetSession()) { if (session.Open() == Session.State.Opened) { // Create a QueueManager to actively manage our queues IQueueManager manager = DeliveryFactory.CreateQueueManager(new QueueManager.Params().Session(session) .Endpoint(researchEndpoint) .OnError((qm, err) => Console.WriteLine(err))); // First, check to see if we have any news headline queues active in the cloud... List <IQueue> queues = manager.GetAllQueues(); // Check the error property to determine the result of the last request if (manager.Error == null) { // Prepare Research criteria if we plan to create a new AWS queue - we must supply a research ID. JObject criteria = new JObject() { ["transport"] = new JObject() { ["transportType"] = "AWS-SQS" }, ["payloadVersion"] = "2.0", ["userID"] = Configuration.Credentials.ResearchID }; // If no existing queue exists, create one. IQueue queue = (queues.Count > 0 ? queues[0] : manager.CreateQueue(criteria)); if (queue != null) { Console.WriteLine($"{Environment.NewLine}{(queues.Count > 0 ? "Using existing" : "Created a new")} queue..."); // Subscribe to the queue. // Note: The subscriber interface has 2 mechanisms to retrieve data from the queue. The first mechanism is to selectively // poll the queue for new messages. The second mechanism is to define a callback/lambda expression and notify the // the subscriber to poll for messages as they come in - this mechansim provides a near realtime result. // // The following example demonstrates the first mechanism. IQueueSubscriber subscriber = DeliveryFactory.CreateQueueSubscriber(new AWSQueueSubscriber.Params().Queue(queue)); Console.WriteLine("Attempt to retrieve research messages. Hit any key to interrupt fetching..."); // Instead of defining a lambda callback, we manually poll the queue until we hit any key on the keyboard. // Each poll will timeout after 5 seconds. bool noMsgAvailable = false; while (!Console.KeyAvailable) { IQueueResponse result = subscriber.GetNextMessage(5); if (result.IsSuccess) { if (result.IsMessageAvailable) { DisplayResearch(result); } else { Console.Write(noMsgAvailable ? "." : "No Message available from GetNextMessage"); } noMsgAvailable = !result.IsMessageAvailable; } else { Console.WriteLine(result.Status); } } Console.ReadKey(); // Prompt the user to delete the queue Console.Write("\nDelete the queue (Y/N) [N]: "); var delete = Console.ReadLine(); if (delete?.ToUpper() == "Y") { if (manager.DeleteQueue(queue)) { Console.WriteLine("Successfully deleted queue."); } else { Console.WriteLine($"Issues deleting queue {manager.Error}"); } } } } } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main(string[] _) { const string newsHeadlinesEndpoint = "https://api.refinitiv.com/message-services/v1/news-headlines/subscriptions"; IQueueManager manager = null; IQueueNode queue = null; try { // Create the platform session. ISession session = Configuration.Sessions.GetSession(); // Open the session session.Open(); // Create a queue definition var definition = Queue.Definition(newsHeadlinesEndpoint); // Create a QueueManager to actively manage our queues manager = definition.CreateQueueManager().OnError((err, qm) => Console.WriteLine(err)); // First, check to see if we have any news headline queues active in the cloud... List <IQueueNode> queues = manager.GetAllQueues(); // Determine if we retrieved an active headline queue...create one if not. if (queues.Count > 0) { queue = queues[0]; } else { // News Expression defining "Alerts only" var alerts = new JObject() { ["repositories"] = new JArray("NewsWire"), ["filter"] = new JObject() { ["type"] = "urgency", ["value"] = "Alert" }, ["maxcount"] = 10, ["relevanceGroup"] = "all" }; queue = manager.CreateQueue(alerts); } // Ensure our queue is created if (queue != null) { Console.WriteLine($"{Environment.NewLine}{(queues.Count > 0 ? "Using existing" : "Created a new")} queue. Waiting for headlines..."); // Subscribe to the queue. // Note: The subscriber interface has 2 mechanisms to retrieve data from the queue. The first mechanism is to selectively // poll the queue for new messages. The second mechanism is to define a callback/lambda expression and notify the // the subscriber to poll for messages as they come in - this mechansim provides a near realtime result. // // The following example demonstrates the first mechanism. var subscriber = definition.CreateAWSSubscriber(queue); // Poll the queue until we hit any key on the keyboard. // Each poll will timeout after 2 seconds if no messages arrive. var task = new CancellationTokenSource(); var run = Task.Run(() => { try { while (!task.IsCancellationRequested) { subscriber.GetNextMessage(20, (headline, s) => DisplayHeadline(headline), task.Token); } } catch (TaskCanceledException) { Console.WriteLine("News polling cancelled by user"); } }); Console.ReadKey(); task.Cancel(); run.GetAwaiter().GetResult(); } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } finally { if (manager is IQueueManager && queue is IQueueNode) { // Prompt the user to delete the queue Console.Write("\nDelete the queue (Y/N) [N]: "); var delete = Console.ReadLine(); if (delete?.ToUpper() == "Y") { if (manager.DeleteQueue(queue)) { Console.WriteLine("Successfully deleted queue."); } else { Console.WriteLine($"Issues deleting queue."); } } } } }