

( " FakeElasticSearchClient-Observer is processing requests to produce valid responses.") ( " FakeElasticSearchClient-Observer has been notified for the coming requests.") Private void ProcessRequests(IList requests)Ĭonsole.ForegroundColor = ConsoleColor.Yellow RequestTimeStamp = ( " o")Ĭlient.PostAsync(customerApiPostAddress, null) Ĭonsole.ForegroundColor = ConsoleColor.Green Ĭonsole.WriteLine( " CustomerApiClient-Provider has posted all the requests!")

Private void PostRequest(IList customers, ref List requests)ĬonfigurationManager.AppSettings Ĭlient.BaseAddress = new Uri(customerApiBaseAddress) If (_observer != null & _observers.Contains(_observer)) Return new Unsubscriber(observers, observer) Public IDisposable Subscribe(IObserver observer) Public class CustomersApiClient : IObservable The observer, in its turn, would query the Elastic Search, retrieve the EventDate, deserializing the requent and ultimately exporting the data to a TSV file. The Provider would forward the notification to the Observer. The provider must implement a single method, Subscribe, that indicates that an observer wants to receive push-based notifications.īasically, I needed a Provider that would be responsible to post requests to the API. No further data by calling IObserver.OnCompleted.An error condition by calling IObserver.OnError.The current data by calling IObserver.OnNext.The observer exposes the following methods: The provider sends notifications to the observer, but before it can do that, the Observer needs subscribe, to the provider, to indicate that it wants to receive push-based notifications.įrom now and on, we will be referring to those two as Provider- Observer. In some push-based notifications, the IObserver implementation and T can represent the same type. T represents the class that provides the notification information. The IObservable interface represents the class that sends notifications (the provider) the IObserver interface represents the class that receives them (the observer). The IObserver and IObservable interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. For this scenario, I felt that it was the perfect solution.

I decided to implement IObserver and IObservable. NET Framework is shifted with a number of interfaces that can help us deliver solutions with more elegant and vigilent code. One would be responsible to start posting to the Web Api and the second console application would be responsible to read from The Elastic Search using the token. I could have done it using two console applications. The file would include Three Columns (Token- RequestDateStamp- EventDateStamp) We needed to automate this flow by triggering thousands of requests, and at the completion, we needed to export data to a TSV file. To retrieve the time, we needed to Post to Elastic Search by adding to the querystring, the Token that we initially posted through the WebApi. We wanted to measure the time it took for the message to be added and retrieved from the EventHub. We were posting events to the EventHub by using WebApi.
#Iobserve github update#
Again, if you need to change that, please update the App.Config. tsv will be generated in the specified location. I have enabled the Nuget Package Restore, so nuget manager will be able to find and add missing assemblies.Īt the end of the process, a. The Observer will start posting GET Requests to the FakeElasticSerach in order to retrieve the date. The Provider will start posting requests to that link, for that reason it's important to run FakeElasticSearch API. If you decide to place it somewhere else, please update the App.config in the Provider project.Īs we don't have access to the real Elastic Search link from here, in order to make this work, I needed to develop a FakeElasticSearch API, which you need to run. In the ObserverPattern attachment, there is a CustomerList.txt file.This is a console application that demonstrates a real example of how we implemented IObservable and IObserver.
