Search code examples
javac#rabbitmqnetwork-programmingamqp

What is the difference between channels and links in AMQP?


I'm am trying to understand the framing part of the AMQP protocol. I get it that AMQP first opens a TCP connection and then uses multiple channels inside this connection to prevent the overhead of setting up multiple TCP connections (this is very well explained here). Now I'm struggling to understand how links come into play. So from my understanding, it works as the follows:

  1. A connection (TCP most of the time) is set up between two containers (two programs basically)
  2. Multiple channels are created. They are not tied to any nodes
  3. A session combines two channels of each direction, still not tied to any nodes
  4. "Links" bind a session to two nodes from each end

Is my understanding correct? Why do we need the concept of "Links" when we already have channels? Why not just make a channel a connection between two nodes? What, in plain english, is the difference between a channel and a link?

Microsoft states:

A channel is a unidirectional, outbound, virtual transfer path on top of the connection.

and

A link is a communication path created over a session that enables transferring messages in one direction

This sounds to me basically the same. I would be very happy if someone could explain in simple terms how cannels, sessions and links are related.


Solution

  • Long story short

    Connections are made out of unidirectional channels which connects two nodes.

    Channels therefore are unidirectional communications between nodes that can compose a connection

    Session are composed of two channels (incoming & outgoing)

    Link protocol is the core of AMQP. A link provides a unidirectional transport between two nodes. A link attaches to a node at a terminus. There are two kinds of terminus: sources and targets. A terminus is responsible for tracking the state of a particular stream of incoming or outgoing messages. Sources track outgoing messages and targets track incoming messages.

    Notice: you can think a terminus as a socket in the client to which you can associate a precise function such as source/target.

    Full explanation

    All the information and images following are coming from the specification of the protocol OASIS Advanced Message Queuing Protocol (AMQP) Version 1.0. For more information you should read this.

    An AMQP network consists of nodes connected via links. Nodes are named entities responsible for the safe storage and/or delivery of messages. Messages can originate from, terminate at, or be relayed by nodes.

    In order for communication to occur between nodes in different containers a connection needs be established. An AMQP connection consists of a full-duplex, reliably ordered sequence of frames. A frame is the unit of work carried on the wire.

    enter image description here

    An AMQP connection is divided into a negotiated number of independent unidirectional channels. An AMQP session correlates two unidirectional channels to form a bidirectional, sequential conversation between two containers.

    enter image description here

    A single connection may have multiple independent sessions active simultaneously, up to the negotiated channel limit. Both connections and sessions are modeled by each peer as endpoints that store local and last known remote state regarding the connection or session in question.

    enter image description here

    In order to transfer messages between nodes a link needs to be established between the nodes. A link is a unidirectional route between two nodes. A link attaches to a node at a terminus. There are two kinds of terminus: sources and targets. A terminus is responsible for tracking the state of a particular stream of incoming or outgoing messages.

    Links provide a credit-based flow control scheme based on the number of messages transmitted, allowing applications to control which nodes to receive messages from at a given point

    enter image description here