Differences between Reactive Programming and Message Queue

Sam :

I'm busy with Reactive concept these days. I have understood two separate concepts as Reactive System and Reactive Programming. In addition, I know Reactive System is a larger concept which contains four properties:

  1. Responsive
  2. Resilient
  3. Scalable
  4. Event-Driven

enter image description here

The Image Reference: medium.com

My problem is about Reactive Programming, I understood that its goal is Asynchronous Programming by Observable/Subscriber model. enter image description here

The Image Reference: https://hub.packtpub.com/introduction-reactive-programming/

Now I'm confused about the difference between Reactive Programming and Message Queue. I have had some experience in Message Oriented Middleware and related standards such as JMS and I think Reactive Programming is the same using messaging queue in listener mode not blocking mode.

I wanted to be clear in Reactive Programming real concept.

Axel Podehl :

Reactive Programming is a new name for old concepts. It means prefer event-driven computing over request-reply computing. Or 'push' versus 'pull'. So instead of writing code that waits for something to arrive, you define callbacks that are executed when something happens. The Observer pattern is a good example of reactive programming and so is the Hollywood Principle ("Don't call us, we'll call you").

In JMS terms, you are doing reactive programming if you defined a MessageListener on your consumer: MessageConsumer.setMessageListener(MessageListener listener)

Then your API or other code can decide what to process in the meantime and if something arrives, from a queue or topic, that callback is invoked.

The alternative, using MessageConsumer.receive(long timeout), is not reactive programming. You are blocking your current thread until the next message arrives.

Thinking in an event-driven or reactive way takes a bit of a leap sometimes, but it is worth the effort.

When looking at the system itself, I would argue that an infrastructure built with topics is a reactive system. An infrastructure built with queues is not.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=86481&siteId=1