By Admin on Saturday, 24 February 2024
Category: All

AMQP 1.0.0 Delphi Client

From sgcWebSockets 2024.2.0 AMQP 1.0.0 is supported.

AMQP (Advanced Message Queuing Protocol) 1.0.0 is a messaging protocol designed for reliable, asynchronous communication between distributed systems. It facilitates the exchange of messages between applications or components in a decoupled manner, allowing them to communicate without direct dependencies. 

Overall, AMQP 1.0.0 provides a standardized and interoperable way for different software components and systems to communicate in a loosely coupled manner, making it suitable for various distributed and enterprise-level applications. 

AMQP Features

Configuration

​The AMQP 1.0.0 client has the property AMQPOptions where you can configure the connection.

The AMQP Authentication must be configured in the Authentication property.

Connection

 The connection starts with the client (usually a messaging application or service) initiating a TCP connection to the server (the message broker). The client connects to the server's port, typically 5672 for non-TLS connections and 5671 for TLS-secured connections. Once the TCP connection is established, the client and server negotiate the AMQP protocol version they will use. AMQP 1.0.0 supports various versions, and during negotiation, both parties agree on using version 1.0.0.

After protocol negotiation, the client may need to authenticate itself to the server, depending on the server's configuration. Authentication mechanisms can include SASL (Simple Authentication and Security Layer) mechanisms like PLAIN, EXTERNAL, or others supported by the server.

Example: connect to AMQP server listening on secure port 5671 and using SASL credentials

Sessions

Once authenticated, the client opens an AMQP session. A session is a logical context for communication between the client and server. Sessions are used to group related messaging operations together. Use the method CreateSession to create a new session, the method allows to set the session name or leave empty and the component will assign automatically one.

If the session has been created successfully, the event OnAMQPSessionOpen will be fired with the details of the session. 

Links

Within a session, the client creates links to communicate with specific entities like queues, topics, or other resources provided by the server. Links are bidirectional communication channels used for sending and receiving messages.

The component can work as a sender and receiver node. Allows to create any number of links for each session, up to the limit set in the MaxLinksPerSession property. 

Sender Links

To create a new sender link, use the method CreateSenderLink and pass the name of the session and optionally the name of the sender link. If the link is created successfully, the event OnAMQPLinkOpen is raised.

Receiver Links

To create a new receiver link, use the method CreateReceiverLink and pass the name of the session and optionally the name of the receiver link. If the link is created successfully, the event OnAMQPLinkOpen is raised. 

Send Messages

With the session established and links created, the client can start performing message operations such as sending messages to a destination. Use the method SendMessage to send a message using a sender link. 

Read Messages

By default, the Receiver Links are created in Automatic mode, which means that every time a new message arrives, it will be delivered to the client.

If the Receiver Links has been created in manual mode, use the Sync Method GetMessage to fetch and wait till a new message arrives.

In Automatic and Manual mode, every time a new message arrives, the event OnAMQPMessage is fired. 

Documentation

sgcWebSockets for Delphi

Download Demo

Download the AMQP 1.0.0 Client Demo compiled for Windows using the sgcWebSockets library. 

Related Posts