Introduction
Configuration
- Publisher Confirms
- Import/Export definitions
- Consumer Cancellation
- Configuration files
- Consumer Acknowledgments
- Prefetch
- Policies
Sample Code
Features
- Dead Letter Exchange
- Consistent Hash Exchange
- Alternate Exchange
- Shovel
- Federation
- RPC
- Direct Reply-to
- Delayed Message Exchange
- Pause Consumers
AMQP 0-9-1 Overview
Queue deep-dive
LavinMQ CLI
Management Interface
Management HTTP API
Tutorials
Security
Monitoring
Development
Support
AMQP Connections and Channels
Connections and channels enable services to communicate within the AMQ Protocol. As for any conversation, parties greet each other, exchange verbal banter, and eventually continue on their way. A similar form of communication occurs over low-level TCP connections exposing lightweight channels in LavinMQ.
What is a connection?
A connection (TCP) is a link between the client and the broker, that performs
underlying networking tasks including initial authentication, IP resolution, and
networking.
What is a channel?
A channel acts as a virtual connection inside a TCP connection.
What benefits do connections and channels provide?
Every AMQP protocol-related operation occurs over a channel. A channel reuses a connection, forgoing the need to reauthorize and open a new TCP stream. Channels allow you to use resources more efficiently.
How should I use connections and channels?
Connections and channels are vital parts of services using AMQP. A service usually needs to have multiple connections communicating with the broker, but instead of having many connections, a service can reuse the connection by creating and deleting channels.
Connection
A connection (TCP/IP) is a link between the client and the broker, that performs underlying networking tasks including initial authentication, IP resolution, and networking.
A connection is created by:
- Opening a physical TCP connection to the target server.
- The client resolves the hostname to one or more IP addresses.
- The receiving server authenticates the client.
- A connection is now established.
LavinMQ supports both IPv4 and IPv6 connections. Connections also have TLS (SSL) support meaning that it is possible to encrypt connections using TLS. In most clients it is easy to use TLS, just replace amqp:// with amqps:// in the URL.
Connections are needed before establishing a channel through a client, to be able to send a message or manage queues. Channels can not be used without the underlying TCP connection. Each connection can maintain a set of underlying channels.
Closing a connection closes all associated channels.
Channel
A channel is needed for crucial communication with the broker. Every AMQP protocol-related operation occurs over a channel, like sending messages or handling queue creation and maintenance. AMQP provides the possibility for one single TCP/IP connection to multiplex into several “light-weight” channels. A channel operates inside a TCP connection.
The channel packages the messages and handles protocol operations. Channels are resource-efficient since they reuse existing channels and minimize the need for resource-heavy openings and closings of new TCP channels.
AMQP commands like declaring queues and declaring exchanges are all sent over a channel. Messages are sent from a client via the channel’s publish method. Remember, closing a connection closes all associated channels.
Code examples:
connection = pika.BlockingConnection(url_params) # Connect to LavinMQ
A channel can be opened right after successfully opening a connection.
channel = connection.channel() # start a channel
Important takeaways (best practice)
Discovering how to optimize the use of channels and connections in your infrastructure and understanding the benefits of reusing channels instead of opening new connections can impact the performance and resources needed to keep applications desirable configured.