Debian Codegraph @

ruby/README.rdoc

raw
1 = Qpid Proton AMQP Library
2
3 This is a library for sending and receiving AMQP messages. It can be used to
4 build clients and servers.
5
6 == Installing
7
8 You can install the latest published Gem with
9
10 gem install qpid_proton
11
12 *NOTE:* before installing the Gem, you must install the proton-C library.
13
14 The proton-C library can be installed by the package manager on many platforms,
15 e.g. yum install qpid-proton-c # Fedora < 25, RHEL < 7 dnf install
16 qpid-proton-c # Fedora >= 25, RHEL >= 7
17
18 You can also download a source release or the latest development code from
19 http://qpid.apache.org/proton. To build from source:
20
21 cmake -DBUILD_BINDINGS=ruby && make
22
23 This produces a Gem file at:
24
25 BUILD_DIR/ruby/qpid_proton-VERSION.gem
26
27 You can install the gem with +gem install+
28
29 == Overview
30
31 {Qpid::Proton::Message} represents a message that can be sent or received. A
32 message body can be a string or byte sequence encoded any way you
33 choose. However, AMQP also provides standard, interoperable encodings for basic
34 data types like {Hash} and {Array}. The equivalent AMQP encodings can be
35 understood as maps or sequences in any programming langauge with an AMQP
36 library.
37
38 {Qpid::Proton::Link} allows messages to be transferred to or from a remote AMQP
39 process. The {Qpid::Proton::Sender} subclass sends messages, the
40 {Qpid::Proton::Receiver} subclass receives them. Links have a source and target
41 address, as explained below.
42
43 Links are grouped in a {Qpid::Proton::Session}. Messages in the same session are
44 sent sequentially, while those on different sessions can be interleaved. A large
45 message being sent on one session does not block messages being sent on another
46 session.
47
48 Sessions belong to a {Qpid::Proton::Connection}. If you don't need multiple
49 sessions, a connection will create links directly using a default session.
50
51 A {Qpid::Proton::Transfer} represents the transfer of a message, the
52 {Qpid::Proton::Delivery} subclass allows a receiver to accept or reject an
53 incoming message. The {Qpid::Proton::Tracker} subclass allows a sender to track
54 the status of a sent message and find out if it was accepted or rejected.
55
56 A transfer is _settled_ when both ends are done with it. Different settlement
57 methods give different levels of reliability: at-most-once, at-least-once, and
58 exactly-once. See below.
59
60 == Anatomy of a Proton application
61
62 {Qpid::Proton::Container} is the top-level object in a Proton application. A
63 client uses {Qpid::Proton::Container#connect} to establish connections. A server
64 uses {Qpid::Proton::Container#listen} to accept connections.
65
66 Proton is an event-driven library. You implement one or more _handlers_ which
67 subclass {Qpid::Proton::MessagingHandler MessagingHandler} and override
68 functions to handle AMQP events, such as {Qpid::Proton::MessagingHandler#on_message
69 #on_message}. Each connection is associated with a handler for its
70 events. {Qpid::Proton::Container#run} polls all connections and listeners and
71 calls the event handling functions on your handlers.
72
73 A multi-threaded application can call {Qpid::Proton::Container#run} in more than
74 one thread, the container will use all the {Qpid::Proton::Container#run #run}
75 threads as a thread pool to dispatch events.
76
77 == Sources and targets
78
79 Every link has two addresses, _source_ and _target_. The most common pattern for
80 using these addresses is as follows:
81
82 When a client creates a {Qpid::Proton::Receiver Receiver} link, it sets the
83 _source_ address. This means "I want to receive messages from this source". This
84 is often referred to as "subscribing" to the source. When a client creates a
85 {Qpid::Proton::Sender Sender} link, it sets the _target_ address. This means "I
86 want to send to this target".
87
88 In the case of a broker, the source or target usually refers to a queue or
89 topic. In general they can refer to any AMQP-capable node.
90
91 In the request-response pattern, a request message carries a reply-to address
92 for the response message. This can be any AMQP address, but it is often useful
93 to create a temporary address for the response message. The client creates a
94 receiver with no source address and the dynamic flag set. The server generates a
95 unique source address for the receiver, which is discarded when the link
96 closes. The client uses this source address as the reply-to when it sends the
97 request, so the response is delivered to the client's receiver.
98
99 The server_direct.cpp example shows how to implement a request-response server.
100
101 == Settling a Message Transfer
102
103 A message transfer is _settled_ at one end of a link when that end of the link
104 has finished with the message and forgotten it.
105
106 _Pre-settled_ messages are settled by the sender before sending. This gives _at
107 most once_ reliability(also known as _best effort_, _unreliable_ or _fire and
108 forget_) since the sender never knows for sure if the message arrived. If the
109 connection is lost before the message is received by the receiver, the message
110 will not be delivered.
111
112 If the sender does not pre-settle a message, then the receiver settles it once
113 it has been processed. The sender is informed of the settlement via the
114 {Qpid::Proton::Tracker Tracker}. If the connection is lost before the sender has
115 received notice of settlement, the delivery is considered in-doubt and the
116 sender can re-send it. This ensures it eventually gets delivered (provided the
117 connection and link can be reestablished) but it is possible for multiple copies
118 of the same message are delivered, so the receiver must be aware of that. This
119 is known as _at_least_once_ reliability.
120
121 == Multi-threaded applications
122
123 {Qpid::Proton::Container#run} can be called by multiple threads concurrently,
124 giving the container a thread-pool to execute handler methods in parallel.
125
126 Instances of {Qpid::Proton::Connection} and objects associated with it
127 ({Qpid::Proton::Session}, {Qpid::Proton::Sender}, {Qpid::Proton::Receiver},
128 {Qpid::Proton::Delivery}, {Qpid::Proton::Tracker}) are not thread-safe and must
129 be used correctly when multiple threads call {Qpid::Proton::Container#run}
130
131 Calls to {Qpid::Proton::MessagingHandler} and {Qpid::Proton::Listener::Handler}
132 methods by the {Qpid::Proton::Container} are automatically serialized for each
133 connection instance.
134
135 Other threads may have code similarly serialized by adding it to the
136 {Qpid::Proton::Connection#work_queue} for the connection. Each object related
137 to a {Qpid::Proton::Connection} also provides a +work_queue+ method.
138
139 You also need to use the {Qpid::Proton::WorkQueue} to communicate between a
140 {Qpid::Proton::MessagingHandler} method call for one connection instance, and a
141 different {Qpid::Proton::Connection} instance in the same container, as separate
142 connections can be processed in parallel.