Introduction
Configuration
Language Support
AMQP 0-9-1 Overview
More Exchange Types
More Consumer Features
Queue Deep-dive
Other Features
Reliable Message Delivery
High Availability
Monitoring
Management HTTP API
Tutorials
Networking
LavinMQ CLI
AMQP Connections and Channels
What is a connection?
A (TCP-)connection is a link between the client and the LavinMQ 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 is the role of channels in the AMQP protocol?
Every AMQP protocol-related operation occurs over a channel. A channel reuses a connection, avoiding the need to reauthorize and open a new TCP stream. Channels use resources more efficiently than opening and closing connections.
A connection is created by:
- Establishing 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.
Example: Establishing a connection
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
LavinMQ supports IPv4, IPv6, and encrypted TLS (SSL) connections. For most clients, TLS is easy to use; replace amqp:// with amqps:// in the URL.
Connections must be established before creating a channel to send messages or manage queues.
Channel
Every AMQP protocol-related operation occurs over a channel, such as sending messages, creating an exchange, or handling queue creation and maintenance. AMQP allows one TCP/IP connection to multiplex into several “lightweight” channels. Channels are resource-efficient since they reuse existing channels and minimize the need for resource-heavy openings and closings of new TCP channels.
Closing a connection closes all associated channels.
A channel can be opened right after successfully opening a connection.
Example: Opening a channel
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
Ready to take the next steps? Here are some things you should keep in mind:
Managed LavinMQ instance on CloudAMQP
LavinMQ has been built with performance and ease of use in mind - we've benchmarked a throughput of about 1,000,000 messages/sec. You can try LavinMQ without any installation hassle by creating a free instance on CloudAMQP. Signing up is a breeze.
Help and feedback
We welcome your feedback and are eager to address any questions you may have about this piece or using LavinMQ. Join our Slack channel to connect with us directly. You can also find LavinMQ on GitHub.