29

I'm quite new to these high level concurrency paradigms, and I've started using the scala RX bindings. So I'm trying to understand how RX differs from messaging queues like RabbitMQ or ZeroMQ?

They both appear to use the subscribe/publish paradigm. Somewhere I saw a tweet about RX being run atop RabbitMQ.

Could someone explain the differences between RX and messaging queues? Why would I choose one over the other? Can one be substituted for the other, or are they mutually exclusive? In what areas do they overlap?

Luciano
  • 2,388
  • 1
  • 22
  • 33
  • 2
    Queues do queueing. Rx does not. Rx is not distributed. Rx is event processing paradigm, not just pub/sub. Events are pub/sub paradigm. – Vadym Chekan Jan 10 '14 at 01:02

2 Answers2

29

It's worth clicking the learn more link on the [system.reactive] tag, we put a fair bit of info there!

From the intro there you can see that Rx is not a message queueing technology:

The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. System.Reactive is the root namespace used through the library. Using Rx, developers represent asychronous data streams using LINQ operators, and parameterize the concurrency in the asynchronous data streams using Schedulers. Simply put, Rx = Observables + LINQ + Schedulers.

So, Rx and message queueing are really distinct technologies that can complement each other quite well. A classic example is a stock price ticker service - this might be delivered via message queuing, but then transformed by Rx to group, aggregate and filter prices.

You can go further: much as Entity Framework turns IQueryable<T> queries into SQL run directly on the database, you can create providers that turn Rx IQbservable<T> queries into native queries - for example a Where filter might leverage the native filtering capability that exists in many message queueing technologies to apply filters directly. This is quite a lot of work though, and hard.

It's much easier, and not uncommon to see message queue messages fed into an Rx Subject so that incoming messages from a queue are transformed into an Rx stream for easy consumption in the client. Rx is also used extensively in GUIs to work with client side events like button presses and text box changes to make traditionally difficult scenarios like drag-n-drop and text auto-completion via asynchronous server queries dramatically easier. There's a good hands on lab covering the later scenario here. It was written against an early release of Rx, but still is very relevant.

I recommend looking at this video presentation by Bart de Smet for a fantastic intro: Curing Your Event Processing Blues with Reactive Extensions (Rx) - including the classic Rx demo that writes a query over a live feed from Kinect to interpret hand-waving!

James World
  • 29,019
  • 9
  • 86
  • 120
  • Nice answer! However,you need be careful with your definition of Reactive Extensions (Rx) and which implementation you are referring to. For example, Rx extensions for Javascript do not incorporate Schedulers etc. – arcseldon Jun 08 '14 at 04:02
  • Bear in mind that `system.reactive` tag is the original .NET version, so I assumed that when answering. – James World Jun 08 '14 at 17:51
  • 1
    fair point, but I am less clear whether the OP was asking for a .NET specific answer. No mention of that in the question. My comment is not to criticise your excellent answer, only to enhance it by considering other implementation perspectives too. – arcseldon Jun 09 '14 at 06:55
  • Worth pointing out. A lot of people do use this tag just because it gets more action than a lot of the ports. – James World Jun 09 '14 at 07:50
  • @arcseldon You're right, indeed I was referring to rx-java when I asked the question, but at the time I wasn't aware it wasn't the first or only implementation; but this isn't clear from the question or tags. – Luciano Jul 10 '14 at 07:07
  • Queuing technologies such as RabbitMQ and ZeroMQ make great candidates for Reactive. I'm in the process of changing a system using RabbitMQ to use Reactive on the client. The system takes a pub/sub stream and makes it an Observer to use anywhere in the client. – Kelly Dec 19 '14 at 03:34
  • Here's a brand new opensourced rxjava-based client library for RabbitMQ that could be of interest: https://github.com/meltwater/rxrabbit – Pelle Oct 13 '16 at 17:39
  • The link is broken, could you please recheck THanks – kuldeep Nov 09 '22 at 14:20
  • It was a decade ago @kuldeep ! :) Still, amazingly managed to find a working link to the demo video for you, now fixed. – James World Nov 11 '22 at 02:38
13

Could someone explain the differences between RX and these other messaging queues?

Rx is simply an abstraction over Events (any kind of event!). Receiving a message from a distributed queue is an Event, and often, ZeroMQ / RabbitMQ solutions often have to use and combine different Events quite a bit, which Rx is very good at.

So often, Rx makes writing ZeroMQ / RabbitMQ apps much easier than it would be otherwise :)

Ana Betts
  • 73,868
  • 16
  • 141
  • 209
  • Your answer sounds good - please can you link to examples where Rx and RabbitMQ are being used cooperatively - for instance do you have Github repo demos etc where Rx is being used as the Consumer of a Rabbit queue etc. Or can you please include skeleton code in your answer. – arcseldon Jun 08 '14 at 03:59
  • I *could* name several investment banks that do this, but I don't want to get sued. :) Suffice to say I can confirm it's a common scenario. – James World Jul 10 '14 at 08:07