Peter Goodman bio photo

Peter Goodman

A software engineer and leader living in Auckland building products and teams. Originally from Derry, Ireland.

Twitter Google+ LinkedIn Github

Pushqa is a smarter pub/sub model, allowing the subscriber to use LINQ to declare the messages they want to receive.

Background

LINQ has revolutionised the way we work with data in .Net, allowing us to compose and query data sources of all types. When Microsoft introduced OData it opened up the ability to query server resources using a simple URI syntax or LINQ if you are using a .Net client. This was great news for accessing data stores like SQL using Entity Framework, NHibernate etc over HTTP such that the data manipulation and querying happens on the server before being sent to the client. A kind of LINQ remoting if you like.

Then came Reactive Extensions (Rx), a LINQ implementation that instead of accessing data sources, allows querying and composition of future events or event streams to produce new event streams. Rx revolutionises the event concept in .Net and makes dealing with asynchrony so much easier.

Introducing Pushqa

Suppose then, that we could also use Rx LINQ or OData uri syntax to filter an event stream of push messages before they leave the source. A kind of smarter Pub/Sub that allows the subscriber to specify which messages they want to receive from the server in a more natural declarative style. This is the goal of Pushqa, to give subscribers power over their own subscriptions.

Imagine a log viewer client that can filter to only the error level messages that happen to a specific user. Or a client cache that listens to specific domain events in order to evict only the items it cares about from it’s cache when they change.

By combining Rx, SignalR and OData Pushqa is able to translate LINQ queries to OData compliant URI conventions. The uri is used to initiate a persistent connection to the server that will then filter the events exposed by an Rx event stream into tailored streams for each client.

e.g.

The following code

eventProvider.Stocks
    .Where(s => 
        s.Name == "GOOG" || 
        s.Name == "MSFT")
    .AsObservable()
    .Subscribe(s => Console.WriteLine(“{0} – {1}”, s.Name, s.Price))

results in the following OData query

http://my.domain.com/Stocks/?filter=(Name eq 'GOOG') or (Name eq 'MSFT')

and the following output

MSFT - 24.11

GOOG - 457.52

MSFT - 30.11

GOOG - 576.65

The stock events generated by the source on the server will be filtered to only Google and Microsoft before being sent to the subscriber one at a time using HTTP long polling or similar HTTP based push messaging as provided by SignalR.

Fetch the early bits from GitHub. Be warned these bits are early but hopefully the sample projects will give you some ideas. Samples include:

  • Using Skip and Take to complete event streams.
  • A Process Viewer showing the server’s process information with live updates.
  • A Stock ticker.
  • WPF and Web examples.