Reactive Extensions (Rx) and .NET

Reactive Extensions (Rx) and .NET 


  The other day I came across a namespace I had not delved into - that of System.Reactive.  ReactiveX or Rx is an older Microsoft technology that a ton of Javascript frameworks spun out from.  It is kinda weird that the origin technology was Microsoft and no one really did anything with it or promoted it.  

   Rx is perfect for the distributed cloud-based applications and web of course.  Rx is focused around the push data propagation rather than the pull. 

                                                                    Focus

                                      Pull                                                     Push

Focus                            client requests, usually has response  server pushes data to clients

Focus2                          get when convenient for client           send when convenient for server

Client/Server control    client is in control                               server is in control

UI focus                        user entry (active)                               passive screen                   

Side Effects                  user convenience/user happy              scalable

Multi-user                    unaware of multi-user                         current state awareness when multi-user 
                                                                          

                                                                     Examples

                                      Pull                                                     Push

UI example                   button clicks  & keyboard entry         GPS & current state dashboard of servers

UI example2                 sensor firing event                              stock market ticker & weather alerts

Email example              "Send/Receive" button                       got new email when someone sent

Web examples               button clicks on web page                 web site available for browser downloads

Web2                             buying something on Ebay                notifications 

Computer Process         data entry                                           batch entry or time sharing

Hardware                       cheap PCs                                         mainframes or web server

Communication             polling                                               notifications

Inventory example        get when user asks - so delay; JIT;    already on hand; inventory

Inventory example2      must order from supplier                   make and send out excess ahead of time



                                                                   Code Impacts

                                      Pull                                                     Push

UI                                  changes b/c user does something       ever-changing current state of things

Code                              "+=" event handlers                           Task<T> 

Collections                    Enumerable collections                      Observable collections 

Collection iteration      Linq arose to address this                    Linq + extra commands required

Patterns                        Event & APIs & Request/Response    Pub/Sub & Observer/Observable

Message Pattern?         yes                                                        yes


    The newer Rx PFX to handle concurrency such as handler locking. Error handling is tougher in Rx.

   Rx gives interfaces for the custom Observer and Observable classes to respond to.  Observable contract has an OnNext, OnError, OnCompletion, and OnSubscription methods. The Observer can Subscribe, Unsubscribe, and Request from the Observable.  Rx returns back an IDisposable that the Observer should dispose in its Dispose() method.


Push/Pull 

  Rx could be combined with some other technology to do a "joint" push/pull propagation.

                                                        Examples

1)  a) Push - start with light-weight notification from server

      b) Pull - if interested, then pull the large payload down

      Perhaps with software updates.

2)  a) Pull - when initializing the display

     b) Push - update thereafter when state actually changes

     Perhaps with GPS so can see where things are initially


Comments

Popular posts from this blog

Upgrading to .NET8 from desktop versions 4.8.X

GHL Chat Bots for Webpage

GHL > Set website so shorter URL address