AdvancedMessagingQueueProtocol (AMQP)
AdvancedMessagingQueueProtocol (AMQP)
AdvancedMessagingQueueProtocol (AMQP)
225
What Is AMQP?
AMQP Architecture
AMQP Communications
Flow Control
AMQP Essentials
B Y PA O LO PATIERNO
W H AT I S A M Q P ?
tied to TCP, and as such can be used with any reliable stream
TR ANSPORT/FR A M ING
A M Q P A RC H I T E C T U R E
AMQP has a layered model defined in the following way
AMQP
JAVAESSENTIALS
ENTERPRISE EDITION 7
D Z O NE, INC.
DZ O NE .C O M
CORE AMQP
M ESSAGING
capabilities.
This layer defines a well-known structure of the message
composed of two main parts :
multiple links.
The bare message contains the body and two types of collections:
the first one is for system properties that are standard and
Regarding the data exchanged, the frame is the atomic unit and
is divided in three main parts:
content.
frame type.
D Z O NE, INC .
DZ O NE .C O M
CORE AMQP
and only if the required QoS is at level one (at least once) and
the messages are not settled by the producer. The receiver can
send only one disposition performative to confirm that it has
processed
There is only one non-terminal state, named Received,
which indicates partial message data or the starting point for
a resumed transfer.
A M Q P CO M M U N I C AT I O N S
All the AMQP conceptsfrom connection, session, and link to
performatives and messagesfit together to define how the
communication happens between two peers. The main steps
involved are:
DZ O NE .C O M
CORE AMQP
happen that its lost in the network and doesnt arrive to the
receiver. The sender doesnt receive any information about
F LO W CO N T RO L
The AMQP protocol provides different ways to do flow
control at different levels. First of all, during the opening
connection process, the two peers negotiate a maximum
frame size that defines the maximum size of each single
frame that can be exchanged.
The first level of flow control is provided by session; each session
endpoint has an incoming and outgoing window with a size
defined as frame count. On both sides (sender and receiver), the
frames exchange can be stopped when the window is full (the
sender doesnt have more window space to send, the receiver
acknowledge is expected.
receiver is able to receive. The receiver can set this value using
the flow performative; for each incoming message the counter
is decremented until a value of zero suspends transfer.
Why are two different flow control levels needed?
The session flow control is useful to protect a Cloud platform at
high-scale when there are million connections and frames; in
this way it can handle capacity management and throttling. In
the IoT space its very useful for very low constrained devices
that have low memory capacity for buffers.
Q U A L I T Y O F S E RV I C E
The AMQP protocol provides the three following Quality of
Service levels related to the messages delivery:
D Z O NE, INC .
DZ O NE .C O M
CORE AMQP
S E C U R I T Y A N D A U T H E N T I C AT I O N
SSL/TLS AND SA SL
LE T S T RY A M Q P
First of all we need to define the base address of the broker for
connecting. For this purpose, the AMQP .Net Lite library exposes
the Address class that we can use in the following way:
Address address
= new Address(amqp://admin:admin@192.168.1.103:5672);
P L AT F O R M S A N D C LI E N TS B A S E D O N A M Q P
Who uses AMQP? What are the main platforms based on AMQP?
The first offer comes from the open-source world thanks to the
Apache Foundation with the Apache Qpid project that provides an
AMQP stack implementation in C, Java, C++ and other languages.
In the same way, there is the AMQP .Net Lite library that is an
open source .Net and C# implementation from Microsoft.
After that we need to create and attach the link with the
destination queue to send data:
The above products are used as clients in most cases but what
about broker/server and enterprise architecture based on AMQP?
D Z O NE, INC .
SenderLink sender
= new SenderLink(session, sender-link, q1);
DZ O NE .C O M
6
At the end of this three steps, the connection is established and
CORE AMQP
SEND M ESSAGE
receiver.SetCredit(10, false);
R E C E I V E M E SS AG E A SYN C H RO N O US LY
RECEIVE M ESSAGE
On the receiver side, the connection and the session are created
in the same way but the attached link is specified using the
ReceiverLink class.
ReceiverLink receiver
= new ReceiverLink(session, receiver-link, q1);
When the peers dont need the channel anymore, they can close
it in the opposite order they open it. First detaching the link then
ending the session and finally closing the connection.
sender.Close(); // or receiver.Close();
session.Close();
connection.Close();
A B O U T T H E AU T H O R
RE S O U R C E S
for Windows Embedded / Internet of Things who has been working on Microsoft
technologies since 2006 with all .Net Frameworks (Micro, Compact and Full);
he has been developing on embedded and mobile systems (based on Windows
CE, WindowsPhone/Android and RTOS) since 2010, using C/C++, C# and
Java. Focused on IoT protocols and on developing end to end solution in the
IoT business on both devices and Cloud side. Member of DotNetCampania,
TinyCLR.it and Embedded101 communities. Technical writer and owner of
some open source projects on GitHub. He blogs at paolopatierno.wordpress.
com and you can follow him on Twitter @ppatierno.
JOIN NOW
DZONE, INC.
150 PRESTON EXECUTIVE DR.
CARY, NC 27513
DZone communities deliver over 6 million pages each month to more than 3.3 million software
developers, architects and decision makers. DZone offers something for everyone, including news,
tutorials, cheat sheets, research guides, feature articles, source code and more.
888.678.0399
919.678.0300
REFCARDZ FEEDBACK WELCOME
refcardz@dzone.com
SPONSORSHIP OPPORTUNITIES
DZ Osales@dzone.com
NE .C O M
Copyright 2016 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
D Zpermission
O NE, INC
transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
of the. publisher.
VERSION 1.0