11

How does AMQP overcome the difficulties of using TCP directly when sending messages? Or more specifically in a pub/sub scenario?

user1577433
  • 501
  • 1
  • 6
  • 12

2 Answers2

12

In AMQP there is a broker, that broker receives the messages and then does the hard part about routing them to exchanges and queues. You can also setup durable queues which save the messages for clients even when they are disconnected.

You could certainly do all this yourself, but it's a tremendous amount of work to do correctly. RabbitMQ in particular has been battle tested in many deployments.

You are still using the TCP protocol underneath AMQP, AMQP provides a higher abstraction.

You would also have to choose a wire protocol to use with all your clients, where AMQP already defines that wired protocol.

hwatkins
  • 1,416
  • 8
  • 11
8

It overcomes difficulties by using one and same TCP connection for all of your threads for performance. AMQP is able to do it by using channels. These channels is a virtual connection inside the “real” TCP connection, and it’s over the channel that you issue AMQP commands.

As each thread spins up, it creates a channel on the existing connection and gets its own private communication path to broker without any additional load on your operating system’s TCP stack.

enter image description here

As a result, you can create a channel hundreds or thousands of times a second without your operating system seeing so much as a blip. There’s no limit to how many AMQP channels you can have on one TCP connection. Think of it like a bundle of fiber optic cable.

Source book: RabbitMq in Action

Farhad Jabiyev
  • 26,014
  • 8
  • 72
  • 98