Skip to content

Commit 7084d49

Browse files
author
Martijn Otto
committed
Updated README
1 parent a957027 commit 7084d49

File tree

1 file changed

+74
-78
lines changed

1 file changed

+74
-78
lines changed

README.md

Lines changed: 74 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class MyConnectionHandler : public AMQP::ConnectionHandler
8686
}
8787

8888
/**
89-
* Method that is called when the connection was closed. This is the
90-
* counter part of a call to Connection::close() and it confirms that the
89+
* Method that is called when the connection was closed. This is the
90+
* counter part of a call to Connection::close() and it confirms that the
9191
* connection was correctly closed.
9292
*
9393
* @param connection The connection that was closed and that is now unusable
@@ -143,12 +143,12 @@ every time that it wants to send out data. We've explained that it is up to you
143143
implement that method. But what about data in the other direction? How does the
144144
library receive data back from RabbitMQ?
145145
146-
The AMQP-CPP library does not do any IO by itself and it is therefore of course
147-
also not possible for the library to receive data from a socket. It is again up
148-
to you to do this. If, for example, you notice in your event loop that the socket
149-
that is connected with the RabbitMQ server becomes readable, you should read out
150-
that socket (for example by using the recv() system call), and pass the received
151-
bytes to the AMQP-CPP library. This is done by calling the parse() method in the
146+
The AMQP-CPP library does not do any IO by itself and it is therefore of course
147+
also not possible for the library to receive data from a socket. It is again up
148+
to you to do this. If, for example, you notice in your event loop that the socket
149+
that is connected with the RabbitMQ server becomes readable, you should read out
150+
that socket (for example by using the recv() system call), and pass the received
151+
bytes to the AMQP-CPP library. This is done by calling the parse() method in the
152152
Connection object.
153153
154154
The Connection::parse() method gets two parameters, a pointer to a buffer of
@@ -160,12 +160,12 @@ The code snippet below comes from the Connection.h C++ header file.
160160
* Parse data that was recevied from RabbitMQ
161161
*
162162
* Every time that data comes in from RabbitMQ, you should call this method to parse
163-
* the incoming data, and let it handle by the AMQP-CPP library. This method returns
163+
* the incoming data, and let it handle by the AMQP-CPP library. This method returns
164164
* the number of bytes that were processed.
165165
*
166-
* If not all bytes could be processed because it only contained a partial frame,
167-
* you should call this same method later on when more data is available. The
168-
* AMQP-CPP library does not do any buffering, so it is up to the caller to ensure
166+
* If not all bytes could be processed because it only contained a partial frame,
167+
* you should call this same method later on when more data is available. The
168+
* AMQP-CPP library does not do any buffering, so it is up to the caller to ensure
169169
* that the old data is also passed in that later call.
170170
*
171171
* @param buffer buffer to decode
@@ -178,19 +178,19 @@ size_t parse(char *buffer, size_t size)
178178
}
179179
````
180180

181-
You should do all the book keeping for the buffer yourselves. If you for example
182-
call the Connection::parse() method with a buffer of 100 bytes, and the method
183-
returns that only 60 bytes were processed, you should later call the method again,
184-
with a buffer filled with the remaining 40 bytes. If the method returns 0, you should
181+
You should do all the book keeping for the buffer yourselves. If you for example
182+
call the Connection::parse() method with a buffer of 100 bytes, and the method
183+
returns that only 60 bytes were processed, you should later call the method again,
184+
with a buffer filled with the remaining 40 bytes. If the method returns 0, you should
185185
make a new call to parse() when more data is available, with a buffer that contains
186186
both the old data, and the new data.
187187

188188

189189
CHANNELS
190190
========
191191

192-
In the example we created a channel object. A channel is a virtual connection over
193-
a single TCP connection, and it is possible to create many channels that all use
192+
In the example we created a channel object. A channel is a virtual connection over
193+
a single TCP connection, and it is possible to create many channels that all use
194194
the same TCP connection.
195195

196196
AMQP instructions are always sent over a channel, so before you can send the first
@@ -203,21 +203,21 @@ documented.
203203

204204
The constructor of the Channel object accepts one parameter: the connection object.
205205
Unlike the connection it does not accept a handler. Instead of a handler object,
206-
(almost) every method of the Channel class returns an instance of the 'Deferred'
207-
class. This object can be used to install handlers that will be called in case
206+
(almost) every method of the Channel class returns an instance of the 'Deferred'
207+
class. This object can be used to install handlers that will be called in case
208208
of success or failure.
209209

210-
For example, if you call the channel.declareExchange() method, the AMQP-CPP library
210+
For example, if you call the channel.declareExchange() method, the AMQP-CPP library
211211
will send a message to the RabbitMQ message broker to ask it to declare the
212212
queue. However, because all operations in the library are asynchronous, the
213213
declareExchange() method can not return 'true' or 'false' to inform you whether
214-
the operation was succesful or not. Only after a while, after the instruction
215-
has reached the RabbitMQ server, and the confirmation from the server has been
214+
the operation was succesful or not. Only after a while, after the instruction
215+
has reached the RabbitMQ server, and the confirmation from the server has been
216216
sent back to the client, the library can report the result of the declareExchange()
217217
call.
218218

219-
To prevent any blocking calls, the channel.declareExchange() method returns a
220-
'Deferred' result object, on which you can set callback functions that will be
219+
To prevent any blocking calls, the channel.declareExchange() method returns a
220+
'Deferred' result object, on which you can set callback functions that will be
221221
called when the operation succeeds or fails.
222222

223223
````c++
@@ -249,9 +249,9 @@ run in either case: when the operation succeeds or when it fails.
249249
250250
The signature for the onError() method is always the same: it gets one parameter
251251
with a human readable error message. The onSuccess() function has a different
252-
signature depending on the method that you call. Most onSuccess() functions
253-
(like the one we showed for the declareExchange() method) do not get any
254-
parameters at all. Some specific onSuccess callbacks receive extra parameters
252+
signature depending on the method that you call. Most onSuccess() functions
253+
(like the one we showed for the declareExchange() method) do not get any
254+
parameters at all. Some specific onSuccess callbacks receive extra parameters
255255
with additional information.
256256
257257
@@ -287,7 +287,7 @@ myChannel.onReady([]() {
287287
});
288288
````
289289

290-
In theory, you should wait for the onReady() callback to be called before you
290+
In theory, you should wait for the onReady() callback to be called before you
291291
send any other instructions over the channel. In practice however, the AMQP library
292292
caches all instructions that were sent too early, so that you can use the
293293
channel object right after it was constructed.
@@ -307,10 +307,10 @@ myChannel.declareQueue("my-queue");
307307
myChannel.declareExchange("my-exchange");
308308
````
309309
310-
If the first declareQueue() call fails in the example above, the second
310+
If the first declareQueue() call fails in the example above, the second
311311
myChannel.declareExchange() method will not be executed, even when this
312312
second instruction was already sent to the server. The second instruction will be
313-
ignored by the RabbitMQ server because the channel was already in an invalid
313+
ignored by the RabbitMQ server because the channel was already in an invalid
314314
state after the first failure.
315315
316316
You can overcome this by using multiple channels:
@@ -322,10 +322,10 @@ channel1.declareQueue("my-queue");
322322
channel2.declareExchange("my-exchange");
323323
````
324324

325-
Now, if an error occurs with declaring the queue, it will not have consequences
326-
for the other call. But this comes at a small price: setting up the extra channel
327-
requires and extra instruction to be sent to the RabbitMQ server, so some extra
328-
bytes are sent over the network, and some additional resources in both the client
325+
Now, if an error occurs with declaring the queue, it will not have consequences
326+
for the other call. But this comes at a small price: setting up the extra channel
327+
requires and extra instruction to be sent to the RabbitMQ server, so some extra
328+
bytes are sent over the network, and some additional resources in both the client
329329
application and the RabbitMQ server are used (although this is all very limited).
330330

331331

@@ -385,9 +385,9 @@ channel.declareQueue("myQueue").onSuccess(callback);
385385
````
386386

387387
Just like many others methods in the Channel class, the declareQueue() method
388-
accept an integer parameter named 'flags'. This is a variable in which you can
389-
set method-specific options, by summing up all the options that are described in
390-
the documentation above the method. If you for example want to create a durable,
388+
accept an integer parameter named 'flags'. This is a variable in which you can
389+
set method-specific options, by summing up all the options that are described in
390+
the documentation above the method. If you for example want to create a durable,
391391
auto-deleted queue, you can pass in the value AMQP::durable + AMQP::autodelete.
392392

393393
The declareQueue() method also accepts a parameter named 'arguments', which is of type
@@ -421,7 +421,7 @@ exchange to publish to, the routing key to use, and the actual message that
421421
you're publishing - all these parameters are standard C++ strings.
422422

423423
More extended versions of the publish() method exist that accept additional
424-
arguments, and that enable you to publish entire Envelope objects. An envelope
424+
arguments, and that enable you to publish entire Envelope objects. An envelope
425425
is an object that contains the message plus a list of optional meta information like
426426
the content-type, content-encoding, priority, expire time and more. None of these
427427
meta fields are interpreted by this library, and also the RabbitMQ ignores most
@@ -441,10 +441,10 @@ in almost any form:
441441
*
442442
* The following flags can be used
443443
*
444-
* - mandatory if set, an unroutable message will be reported to the
444+
* - mandatory if set, an unroutable message will be reported to the
445445
* channel handler with the onReturned method
446-
*
447-
* - immediate if set, a message that could not immediately be consumed
446+
*
447+
* - immediate if set, a message that could not immediately be consumed
448448
* is returned to the onReturned method
449449
*
450450
* If either of the two flags is set, and the message could not immediately
@@ -469,17 +469,17 @@ bool publish(const std::string &exchange, const std::string &routingKey, const c
469469
470470
Published messages are normally not confirmed by the server, and the RabbitMQ
471471
will not send a report back to inform us whether the message was succesfully
472-
published or not. Therefore the publish method does also not return a Deferred
472+
published or not. Therefore the publish method does also not return a Deferred
473473
object.
474474
475-
As long as no error is reported via the Channel::onError() method, you can safely
475+
As long as no error is reported via the Channel::onError() method, you can safely
476476
assume that your messages were delivered.
477477
478-
This can of course be a problem when you are publishing many messages. If you get
479-
an error halfway through there is no way to know for sure how many messages made
480-
it to the broker and how many should be republished. If this is important, you can
478+
This can of course be a problem when you are publishing many messages. If you get
479+
an error halfway through there is no way to know for sure how many messages made
480+
it to the broker and how many should be republished. If this is important, you can
481481
wrap the publish commands inside a transaction. In this case, if an error occurs,
482-
the transaction is automatically rolled back by RabbitMQ and none of the messages
482+
the transaction is automatically rolled back by RabbitMQ and none of the messages
483483
are actually published.
484484
485485
````c++
@@ -531,21 +531,17 @@ The full documentation from the C++ Channel.h headerfile looks like this:
531531
*
532532
* The following flags are supported:
533533
*
534-
* - nolocal if set, messages published on this channel are
534+
* - nolocal if set, messages published on this channel are
535535
* not also consumed
536536
*
537-
* - noack if set, consumed messages do not have to be acked,
537+
* - noack if set, consumed messages do not have to be acked,
538538
* this happens automatically
539539
*
540-
* - exclusive request exclusive access, only this consumer can
540+
* - exclusive request exclusive access, only this consumer can
541541
* access the queue
542542
*
543-
* - nowait the server does not have to send a response back
544-
* that consuming is active
545-
*
546543
* The method ChannelHandler::onConsumerStarted() will be called when the
547-
* consumer has started (unless the nowait option was set, in which case
548-
* no confirmation method is called)
544+
* consumer has started.
549545
*
550546
* @param queue the queue from which you want to consume
551547
* @param tag a consumer tag that will be associated with this consume operation
@@ -561,14 +557,14 @@ DeferredConsumer &consume(const std::string &queue, int flags = 0);
561557
DeferredConsumer &consume(const std::string &queue, const AMQP::Table &arguments);
562558
````
563559
564-
As you can see, the consume method returns a DeferredConsumer. This object is a
565-
regular Deferred, with additions. The onSuccess() method of a
560+
As you can see, the consume method returns a DeferredConsumer. This object is a
561+
regular Deferred, with additions. The onSuccess() method of a
566562
DeferredConsumer is slightly different than the onSuccess() method of a regular
567563
Deferred object: one extra parameter will be supplied to your callback function
568564
with the consumer tag.
569565
570566
The onSuccess() callback will be called when the consume operation _has started_,
571-
but not when messages are actually consumed. For this you will have to install
567+
but not when messages are actually consumed. For this you will have to install
572568
a different callback, using the onReceived() method.
573569
574570
````c++
@@ -588,7 +584,7 @@ auto errorCb = [](const char *message) {
588584
auto messageCb = [&channel](const AMQP::Message &message, uint64_t deliveryTag, bool redelivered) {
589585
590586
std::cout << "message received" << std::endl;
591-
587+
592588
// acknowledge the message
593589
channel.ack(deliveryTag);
594590
}
@@ -601,33 +597,33 @@ channel.consume("my-queue")
601597
602598
````
603599

604-
The Message object holds all information of the delivered message: the actual
605-
content, all meta information from the envelope (in fact, the Message class is
606-
derived from the Envelope class), and even the name of the exchange and the
607-
routing key that were used when the message was originally published. For a full
600+
The Message object holds all information of the delivered message: the actual
601+
content, all meta information from the envelope (in fact, the Message class is
602+
derived from the Envelope class), and even the name of the exchange and the
603+
routing key that were used when the message was originally published. For a full
608604
list of all information in the Message class, you best have a look at the
609605
message.h, envelope.h and metadata.h header files.
610606

611-
Another important parameter to the onReceived() method is the deliveryTag parameter.
612-
This is a unique identifier that you need to acknowledge an incoming message.
613-
RabbitMQ only removes the message after it has been acknowledged, so that if your
614-
application crashes while it was busy processing the message, the message does
615-
not get lost but remains in the queue. But this means that after you've processed
616-
the message, you must inform RabbitMQ about it by calling the Channel:ack() method.
607+
Another important parameter to the onReceived() method is the deliveryTag parameter.
608+
This is a unique identifier that you need to acknowledge an incoming message.
609+
RabbitMQ only removes the message after it has been acknowledged, so that if your
610+
application crashes while it was busy processing the message, the message does
611+
not get lost but remains in the queue. But this means that after you've processed
612+
the message, you must inform RabbitMQ about it by calling the Channel:ack() method.
617613
This method is very simple and takes in its simplest form only one parameter: the
618614
deliveryTag of the message.
619615

620-
Consuming messages is a continuous process. RabbitMQ keeps sending messages, until
621-
you stop the consumer, which can be done by calling the Channel::cancel() method.
616+
Consuming messages is a continuous process. RabbitMQ keeps sending messages, until
617+
you stop the consumer, which can be done by calling the Channel::cancel() method.
622618
If you close the channel, or the entire TCP connection, consuming also stops.
623619

624-
RabbitMQ throttles the number of messages that are delivered to you, to prevent
625-
that your application is flooded with messages from the queue, and to spread out
626-
the messages over multiple consumers. This is done with a setting called
627-
quality-of-service (QOS). The QOS setting is a numeric value which holds the number
620+
RabbitMQ throttles the number of messages that are delivered to you, to prevent
621+
that your application is flooded with messages from the queue, and to spread out
622+
the messages over multiple consumers. This is done with a setting called
623+
quality-of-service (QOS). The QOS setting is a numeric value which holds the number
628624
of unacknowledged messages that you are allowed to have. RabbitMQ stops sending
629-
additional messages when the number of unacknowledges messages has reached this
630-
limit, and only sends additional messages when an earlier message gets acknowledged.
625+
additional messages when the number of unacknowledges messages has reached this
626+
limit, and only sends additional messages when an earlier message gets acknowledged.
631627
To change the QOS, you can simple call Channel::setQos().
632628

633629

0 commit comments

Comments
 (0)