Curing Your Event Processing Blues with Reactive Extensions (Rx)

Slides:



Advertisements
Similar presentations
Reactive Extension to .NET
Advertisements

Slides license: Creative Commons Attribution Non-Commercial Share Alike See
Het Asynchrone Microsoft Landschap Kees Dijk Senior Software Developer, Vivens
An Introduction to the Reactive Extensions Ivan Towlson Mindscape.
DEV324 C# VB 7.0 Managed Code C# VB 8.0 Generics C# VB 9.0 Language Integrated Query C# VB 10.0 Dynamic + Language Parity.
Bing it on, Reactive Extensions Building a quick search app from scratch in WPF with Rx and Bing.com.
Demystifying the .NET Asynchronous Programming Landscape
Introducing the New Visual Studio 2012 Unit Testing Experience Peter Provost Sr. Program Manager Lead Microsoft Corporation DEV214.
Windows Azure SQL Reporting Dany Hoter Senior Program Manager Microsoft Corporation Ola Lavi Software Development Engineer Microsoft Corporation.
Rx Framework Reactive Extensions for.Net and JavaScript Andrea Nasoni & Diego Guidi.
Configuring Hybrid Exchange the Easy Way
Branding and Customizing My Sites with Microsoft SharePoint Server 2010 John Ross & Randy Drisgill MVPs Rackspace Hosting OSP337.
Building Metro style UIs Paul Gusmorino Lead Program Manager Microsoft Corporation DEV354.
Building, Running, and Managing Workflows on Windows Azure Jürgen Willis Group Program Manager Microsoft Corporation.
Building Metro style apps with HTML and JavaScript Paul Gusmorino Lead Program Manager Microsoft Corporation.
LINQ, Take Two Realizing the LINQ to Everything Dream Bart J.F. De Smet Senior Software Development Engineer Microsoft Corporation.
Preparing to Support Enterprise Applications on Windows Azure Eric Mattingly Service Engineer Microsoft Corporation AZR301.
The Dirty Dozen: Windows PowerShell Scripts for the Busy DBA Ike Ellis.
Reactive Extensions Ye olde introduction and walk-through, with plenty o’ code.
Building Metro style apps with HTML and JavaScript Paul Gusmorino Lead Program Manager Microsoft Corporation.
Advanced Microsoft SharePoint 2010 Upgrade Troubleshooting Todd Klindt SharePoint Nerd Rackspace OSP339.
Monads Steve Goguen. About Me Web Developer for Allied Building Supply  ASP.NET, SQL Server, LINQ, etc. Website:
John Plummer Technical Specialist Data Platform Microsoft Ltd StreamInsight Complex Event Processing (CEP) Platform.
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
DEV411 Testing Un-Testable Code with Visual Studio 2012 Fakes Peter Provost Sr. Program Manager Lead Microsoft Corporation DEV411.
Using the Windows Server 2012 Server Manager for Remote and Multi-Server Management Ian Lucas Principal Program Manager Microsoft Corporation WSV335.
App Controller Richard Rundle Ketan Ghelani Program Managers Microsoft Corporation MGT303.
Reactive Extensions (Rx) Explained Presenter: Kevin Grossnicklaus August 5 th, 2011.
LINQ, Take Two Realizing the LINQ to Everything Dream Bart J.F. De Smet blogs.bartdesmet.net/bart
ASP.NET for Mobile and Tablet Development Damian Edwards Senior Program Manager Microsoft Corporation.
Paul Using Rx; 8 November 2014 Raleigh Code Camp.
Windows Phone: Building Enterprise Apps Rob Tiffany Architect Microsoft Corporation WPH207.
Please visit m.ausalgo.com on your device and sign inm.ausalgo.com.
What’s New with IIS 8: Open Web Platform for Cloud Shaun Eagan Senior Program Manager Microsoft Corporation Wade A. Hilmo Principal Development Lead Microsoft.
Demystifying Forefront Edge Security Technologies – TMG and UAG Richard Hicks Director – Sales Engineering Celestix Networks, Inc. SIA208.
1 Lecture 22 Reactive Programming with Rx Duality between Push and Pull models, Iterable vs. Observable. Composing two asynchronous services. Ras Bodik.
Taking Control of Visual Studio through Extensions and Extensibility Anthony Cangialosi Senior Program Manager Lead Microsoft Corporation DEV311.
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
What’s New in WCF 4.5? Richard Blewett Rock Solid Knowledge Ltd DEV326.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Application Lifecycle Management Tools for C++ in Visual Studio 2012 Rong Lu Program Manager Visual C++ Microsoft Corporation DEV316.
Bart J.F. De Smet Software Development Engineer Microsoft Corporation Session Code: DTL315.
2 Complex Event Processing (CEP) is the continuous and incremental processing of event streams from multiple sources based on declarative query and pattern.
Microsoft SQL Server Data Tools: Database Development from Zero to Sixty Gert Drapers Principal Group Program Manager Microsoft Corporation.
What’s New in.NET 4.5 Layla Driscoll Senior Program Manager Microsoft Corporation.
MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.
What web developers need to know when building Metro style apps Scott Dickens Principal Program Manager Lead Microsoft Corporation DEV352.
C# Present and Future Marita Paletsou Software Engineer.
Async Made Simple in Windows 8, with C# and Visual Basic Alex Turner Program Manager VB/C# Compilers Microsoft Corporation DEV332.
Making Agile Estimation Work Joel Semeniuk and Stephen Forte Microsoft Corporation AAP309.
THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.
Going Beyond F11: Debug Better and Faster with Visual Studio 2012 Brian A. Randell Senior Consultant MCW Technologies DEV317.
Building Metro style apps with XAML with.NET Tim Heuer Program Manager Microsoft Corporation DEV353.
The Future of C# and Visual Basic
Using Microsoft Visual Basic to Build Windows Phone Applications
Async or Parallel? No they aren’t the same thing!
9/11/2018 5:53 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
12 Asynchronous Programming
11/23/2018 8:30 AM BRK3037 BRK3037: Dive deep on building apps and services with the Office 365 Communications Platform David Newman Senior Program Manager.
12/2/2018 4:10 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Real World Developer Testing
Using Windows Runtime and SDK to build Metro style apps
TechEd /9/2018 4:17 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
DEV422 Becoming a C# Time Lord Joe Albahari 2/5/ :46 AM
Serverless Architecture in the Cloud
ASP.NET Roadmap: One ASP.NET – Web Forms, MVC, Web API, and more
TechEd /3/ :48 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Developer Collaboration with Team Foundation Server 2012
5/24/ :22 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Server & Tools Business
Presentation transcript:

Curing Your Event Processing Blues with Reactive Extensions (Rx) 4/19/2017 6:11 AM Curing Your Event Processing Blues with Reactive Extensions (Rx) Bart J.F. De Smet Senior Software Development Engineer Microsoft Corporation © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

The Event Processing Landscape GPS RSS feeds Stock tickers Social media UI events Server management

Reactive Extensions Architecture LINQ to Events from quote in stock where quote.Symbol == “MSFT” select quote.Value Projection Filtering Aggregating Grouping Joins Windowing Sharing Sampling Throttling Timeout Merging Recovery Event Streams IObservable<T> IObserver<T> ISubject<T> Concurrency IScheduler Time Threads Cloud Dispatchers

Reactive Extensions Architecture LINQ to Events from quote in stock where quote.Symbol == “MSFT” select quote.Value Projection Filtering Aggregating Grouping Joins Windowing Sharing Sampling Throttling Timeout Merging Recovery Event Streams IObservable<T> IObserver<T> ISubject<T> Concurrency IScheduler Time Threads Cloud Dispatchers

Event Streams Towards a unified programming model Observable Observer Producers are observable sequences .NET events, WinRT events, sensor APIs, APM methods, tasks, etc. Consumers are observers Hooking up “continuations” or handlers Observable Observer Subscribe

Essential Interfaces namespace System { public interface IObservable<out T> IDisposable Subscribe(IObserver<T> observer); } public interface IObserver<in T> void OnNext(T value); void OnError(Exception error); void OnCompleted();

OnNext* (OnError | OnCompleted)? Notification Grammar OnNext(42) OnNext(43) OnCompleted source1 OnNext(“Hello”) OnError(error) source2 OnNext* (OnError | OnCompleted)?

Limitations of .NET Events Can’t pass around Hidden data source exchange.StockTick += (sender, args) => { if (args.Quote.Symbol == “MSFT”) // Imperative code } }; exchange.StockTick -= /* what goes here? */; Lack of composition Hard resource maintenance

Observable Sequences to the Rescue Source of Quotes Objects can be passed IObservable<Quote> stockQuotes = …; var msft = stockQuotes .Where(quote => quote.Symbol == “MSFT”); var subscription = msft.Subscribe(quote => /* … */); subscription.Dispose(); Can define query operators Easy resource maintenance

Are .NET Events Obsolete? Code centric Design-time experience Not first class Non-compositional Lightweight Rigid execution model (IL) Observables Data centric No design-time experience First class objects Rich composition Slightly more cost Translatable with expression trees

Events versus Observables 4/19/2017 6:11 AM demo Events versus Observables Bart J.F. De Smet Senior Software Development Engineer Cloud Programmability Team © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Reactive Extensions Architecture LINQ to Events from quote in stock where quote.Symbol == “MSFT” select quote.Value Projection Filtering Aggregating Grouping Joins Windowing Sharing Sampling Throttling Timeout Merging Recovery Event Streams IObservable<T> IObserver<T> ISubject<T> Concurrency IScheduler Time Threads Cloud Dispatchers

Dictionary Suggest Asynchronous request “React” Dictionary web service 4/19/2017 6:11 AM Dictionary Suggest Asynchronous request IObservable<string> “React” React Dictionary web service Reaction Reactive Reactor IObservable<DictionaryWord[]> Data binding on UI thread © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Converting Events and Asynchronous Methods // Convert the TextChanged event to IObservable<string> var input = (from evt in Observable.FromEventPattern(txt, “TextChanged”) select ((TextBox)evt.Sender).Text) .Throttle(TimeSpan.FromSeconds(0.5)) .DistinctUntilChanged(); // Convert asynchronous proxy methods to Func<string, IObservable<string[]>> var lookup = Observable.FromAsyncPattern<string, string[]>(svc.BeginLookup, svc.EndLookup); // Compose both sources using a query var res = from term in input from words in lookup(term).TakeUntil(input) select words; No longer needed in Rx v2.0 for .NET 4.5, using Task<T>

Querying Event Streams demo Querying Event Streams Bart J.F. De Smet Senior Software Development Engineer Cloud Programmability Team © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Stock Trade Analysis from tick in ticks ticks MSFT 27.01 INTC 21.75 4/19/2017 6:11 AM Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73 ticks from tick in ticks © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Stock Trade Analysis group tick by tick.Symbol ticks MSFT INTC MSFT 4/19/2017 6:11 AM Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73 ticks 27.01 27.96 31.21 30.73 MSFT 21.75 22.54 20.98 INTC from tick in ticks group tick by tick.Symbol © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Stock Trade Analysis group tick by tick.Symbol into company 4/19/2017 6:11 AM Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73 ticks [27.01, 27.96] [27.96, 31.21] [31.21, 30.73] MSFT [21.75, 22.54] [22.54, 20.98] INTC from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4/19/2017 6:11 AM Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73 ticks 0.034 0.104 -0.015 MSFT 0.036 -0.069 INTC from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) let diff = (openClose[1] – openClose[0]) / openClose[0] © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Stock Trade Analysis where diff > 0.1 ticks MSFT INTC MSFT 27.01 4/19/2017 6:11 AM Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73 ticks 0.034 0.104 -0.015 MSFT 0.036 -0.069 INTC from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) let diff = (openClose[1] – openClose[0]) / openClose[0] where diff > 0.1 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4/19/2017 6:11 AM Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73 ticks res Company = MSFT Increase = 0.104 from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) let diff = (openClose[1] – openClose[0]) / openClose[0] where diff > 0.1 select new { Company = company.Key, Increase = diff } © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Complex Event Processing 4/19/2017 6:11 AM demo Complex Event Processing Bart J.F. De Smet Senior Software Development Engineer Cloud Programmability Team © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Reactive Extensions Architecture LINQ to Events from quote in stock where quote.Symbol == “MSFT” select quote.Value Projection Filtering Aggregating Grouping Joins Windowing Sharing Sampling Throttling Timeout Merging Recovery Event Streams IObservable<T> IObserver<T> ISubject<T> Concurrency IScheduler Time Threads Cloud Dispatchers

The Role of Schedulers Parameterize Concurrency // // Runs a timer on the default scheduler IObservable<long> Timer(TimeSpan dueTime); // Every operator that introduces concurrency // has an overload with an IScheduler IObservable<long> Timer(TimeSpan dueTime, IScheduler scheduler);

The Role of Schedulers Synchronization var xs = Observable.Return(42, Scheduler.ThreadPool); xs.Subscribe(x => lbl.Text = "Answer = " + x); xs.ObserveOn( frm ) .Subscribe(x => lbl.Text = "Answer = " + x); xs.ObserveOn(new ControlScheduler(frm)) .Subscribe(x => lbl.Text = "Answer = " + x);

The IScheduler Interface public interface IScheduler { DateTimeOffset Now { get; } IDisposable Schedule<TState>( TState state, Func<IScheduler, TState, IDisposable> action); IDisposable Schedule<TState>( TimeSpan dueTime, TState state, IDisposable Schedule<TState>( DateTimeOffset dueTime, TState state, }

Operational Layering of Rx public static IObservable<T> Return<T>(T value, IScheduler scheduler) { return Observable.Create<T>(observer => // Serialize state to scheduler; return ability to cancel return scheduler.Schedule(new { value, observer }, (_, x) => x.observer.OnNext(x.value); x.observer.OnCompleted(); return Disposable.Empty; // No recursive work }); }

Virtualizing Time for Testing var scheduler = new TestScheduler(); var input = scheduler.CreateHotObservable( OnNext(300, “Bart De Smet”), OnNext(400, “Erik Meijer”), OnCompleted<string>(500) ); var results = scheduler.Start(() => from name in input select name.Length); results.Messages.AssertEqual( OnNext(300, 12), OnNext(400, 11), OnCompleted<int>(500)

Testing in Virtual Time 4/19/2017 6:11 AM demo Testing in Virtual Time Bart J.F. De Smet Senior Software Development Engineer Cloud Programmability Team © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Expression Tree Representation of Queries Runtime translation of reactive queries Like IQueryable<T> for classic LINQ Examples: LINQ to WMI Events Translates LINQ queries into WQL statements LINQ to PowerShell Translates LINQ queries into PowerShell pipelines LINQ to Twitter Translates LINQ queries into Twitter queries Etc.

The IQbservable<T> Interface public interface IQbservable<out T> : IObservable<T> { Type ElementType { get; } Expression Expression { get; } IQbservableProvider Provider { get; } } public interface IQbservableProvider IQbservable<T> CreateQuery<T>(Expression expression);

The Query Processing Landscape Local execution (in-process IL) Query language translation IQueryable<T> IQbservable<T> Expression trees LINQ to SQL (T-SQL) Expression trees LINQ to WMI (WQL) LINQ IEnumerable<T> IObservable<T> Iterators (yield) LINQ to Objects Observable.Create LINQ to Events (Rx) Pull-based Push-based

demo LINQ to WMI Events Bart J.F. De Smet 4/19/2017 6:11 AM demo LINQ to WMI Events Bart J.F. De Smet Senior Software Development Engineer Cloud Programmability Team © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

announcing StreamInsight v2.1 Now with support for hosting Rx v1.0 queries using IQbservable<T> © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

The Future of Rx Support for .NET Framework 4.5 Synergy with asynchronous programming features Prefer using Task<T> for single-value asynchrony Deprecation of FromAsyncPattern Convert to IObservable<T> for more power Use IObservable<T> for event streams Await support returns last value Reduce blocking operations Deprecation of First, Last, Single, ForEach Leveraging new platform capabilities E.g. ExceptionDispatchInfo

The Asynchronous Programming Landscape Single value (1) Multiple values (*) IEnumerable<T> IObservable<T> var res = from p in products where p.Name == “Rx” select p.Price; foreach (var x in res) … var res = from s in stocks where s.Symbol == “MSFT” select q.Quote res.Subscribe(x => … Func<T> Task<T> var y = f(x); var z = g(y); var y = await fAsync(x); var z = await gAsync(y); Synchronous Asynchronous

Imperative glue ~ WaitForMultipleObjectsEx Async without Rx… async Task<string> GetHtmlAsync(Uri url) { var client = new WebClient(); var download = client.DownloadStringAsync(url); var timeout = Task.Delay(TimeSpan.FromSeconds(30)); if (await Task.WhenAny(download, timeout) == timeout) throw new TimeoutException(); var html = await download; return html; } Imperative glue ~ WaitForMultipleObjectsEx

Async with Rx… Better together! async Task<string> GetHtmlAsync(Uri url) { var client = new WebClient(); var download = client.DownloadStringAsync(url) .ToObservable() .Timeout(TimeSpan.FromSeconds(30)); var html = await download; return html; } Composition of query operators Await support for IObservable<T>

The Future of Rx Interoperability with WinRT Use WinRT-style events with FromEventPattern Different method signatures in IL New IScheduler implementations For WinRT ThreadPool and CoreDispatcher ObserveOnDispatcher and SubscribeOnDispatcher support Conversions of IAsync* types Smooth interop with WinRT asynchronous operations Support for progress tracking using IObservable<T>

The Future of Rx Towards Portable Library Support System.Reactive.PlatformServices Platform Enlightenments System.Reactive.Providers Expression tree support Windows.Threading System.Reactive. Windows.Forms System.Reactive. WindowsRuntime System.Reactive. System.Reactive. Remoting System.Reactive.Linq Query operators System.Reactive.Core Base classes, core schedulers, extensions methods System.Reactive.Interfaces Stable interfaces for forward compatibility

The Future of Rx Performance Reducing locking in subjects [3x] Faster producers [100-1000x] New ISchedulerLongRunning interface Pipeline throughput [4x] One call frame per operator Reduced wrapping of observers Less operators defined in terms of others Eliminating redundant locks Eradicating time skew due to timing issues Play nicer with GC

demo Preview of Rx v2.0 Bart J.F. De Smet 4/19/2017 6:11 AM demo Preview of Rx v2.0 Bart J.F. De Smet Senior Software Development Engineer Cloud Programmability Team © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Summary Tame your event streams using Rx and LINQ! Download Rx today! Through http://www.microsoft.com/download (search for Rx SDK) Using NuGet @ www.nuget.org (search for Rx-Main) Now available: Rx v2.0 RC Watch videos at http://channel9.msdn.com/tags/Rx Visit our forums on MSDN

Related Content DEV414 – LINQ, Take Two – Realizing the LINQ to Everything Dream Find Me Later This Week In The Ask The Experts Area

Resources Learning TechNet http://europe.msteched.com Connect. Share. Discuss. http://europe.msteched.com Microsoft Certification & Training Resources www.microsoft.com/learning TechNet Resources for IT Professionals http://microsoft.com/technet Resources for Developers http://microsoft.com/msdn

Submit your evals online 4/19/2017 6:11 AM Evaluations Submit your evals online http://europe.msteched.com/sessions © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4/19/2017 6:11 AM © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.