Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ to RabbitMQ has to be set up.

An example compilation command for an application using the TCP module:
```bash
g++ -g -Wall -lamqcpp -lpthread -ldl my-amqp-cpp.c -o my-amqp-cpp
g++ -std=c++17 -g -Wall -lamqcpp -lpthread -ldl my-amqp-cpp.c -o my-amqp-cpp
```

HOW TO USE AMQP-CPP
Expand Down Expand Up @@ -710,7 +710,7 @@ it has a couple of open issues.

| TCP Handler Impl | Header File Location | Sample File Location |
| ----------------------- | ---------------------- | ------------------------- |
| Boost asio (io_service) | include/libboostasio.h | examples/libboostasio.cpp |
| Boost asio | include/libboostasio.h | examples/libboostasio.cpp |
| libev | include/libev.h | examples/libev.cpp |
| libevent | include/libevent.h | examples/libevent.cpp |
| libuv | include/libuv.h | examples/libuv.cpp |
Expand Down Expand Up @@ -770,7 +770,7 @@ class MyTcpHandler : public AMQP::TcpHandler
````

If you enable heartbeats, it is your own responsibility to ensure that the
```connection->heartbeat()``` method is called at least once during this period,
`connection->heartbeat()` method is called at least once during this period,
or that you call one of the other channel or connection methods to send data
over the connection. Heartbeats are sent by the server too, RabbitMQ also ensures
that _some data_ is sent over the connection from the server to the client
Expand Down Expand Up @@ -925,7 +925,7 @@ channel2.declareExchange("my-exchange");

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

Expand Down Expand Up @@ -1097,7 +1097,7 @@ bool publish(const std::string &exchange, const std::string &routingKey, const c
Published messages are normally not confirmed by the server, and the RabbitMQ
will not send a report back to inform you whether the message was successfully
published or not. But with the flags you can instruct RabbitMQ to send back
the message if it was undeliverable. In you use these flags you must also install
the message if it was undeliverable. If you use these flags you must also install
callbacks that will process these bounced messages.

You can also use transactions to ensure that your messages get delivered.
Expand Down Expand Up @@ -1146,7 +1146,7 @@ the server starts counting the received messages (starting from 1) and sends
acknowledgments for every message it processed (it can also acknowledge
multiple message at once).

If server is unable to process a message, it will send send negative
If server is unable to process a message, it will send negative
acknowledgments. Both positive and negative acknowledgments handling are
passed to callbacks that you can install on the object that
is returned by the `confirmSelect()` method:
Expand Down Expand Up @@ -1190,7 +1190,7 @@ operations are individually acknowledged:
// create a channel
AMQP::TcpChannel mychannel(connection);

// wrap the channel into a reliable-object so that publish-opertions are
// wrap the channel into a reliable-object so that publish-operations are
// individually confirmed (after wrapping the channel, it is recommended
// to no longer make direct calls to the channel)
AMQP::Reliable reliable(mychannel);
Expand Down Expand Up @@ -1289,7 +1289,7 @@ for (size_t i = 0; i < 100000; ++i)
}
````

For more information, see http://www.rabbitmq.com/confirms.html.
For more information, see http://www.rabbitmq.com/docs/confirms.

CONSUMING MESSAGES
==================
Expand Down
68 changes: 43 additions & 25 deletions examples/libboostasio.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/**
* LibBoostAsio.cpp
*
* Test program to check AMQP functionality based on Boost's asio io_service.
*
*
* Test program to check AMQP functionality based on Boost's asio io_context.
*
* @author Gavin Smith <gavin.smith@coralbay.tv>
*
* Compile with g++ -std=c++14 libboostasio.cpp -o boost_test -lpthread -lboost_system -lamqpcpp
* Compile with:
* g++ -std=c++17 -Wall libboostasio.cpp -o boost_test -lboost_system -lamqpcpp -lpthread -ldl
*/

/**
* Dependencies
*/
#include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/deadline_timer.hpp>

#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>

#include <amqpcpp.h>
#include <amqpcpp/libboostasio.h>
Expand All @@ -25,32 +24,51 @@
*/
int main()
{

// access to the boost asio handler
// note: we suggest use of 2 threads - normally one is fin (we are simply demonstrating thread safety).
boost::asio::io_service service(4);
boost::asio::io_context context;

// set of signal for process termination (CTRL-C, kill)
boost::asio::signal_set signals(context, SIGINT, SIGTERM);

// handler for libboostasio
AMQP::LibBoostAsioHandler handler(context);

// handler for libev
AMQP::LibBoostAsioHandler handler(service);

// make a connection
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://guest:guest@localhost/"));

// we need a channel too
AMQP::TcpChannel channel(&connection);


channel.onReady([&signals, &connection]() {
std::cout << "hit CTRL-C to exit\n\nchannel ready\n";

// install the signals handler
signals.async_wait([&connection](const boost::system::error_code& ec, int /* signal_number */)
{
if (!ec) {
// now we gently close the connection
std::cerr << "\nclosing connection...\n";
connection.close();
}
});
});
channel.onError([](const char *message) {
std::cerr << "channel error: " << message << std::endl;
});

// create a temporary queue
channel.declareQueue(AMQP::exclusive).onSuccess([&connection](const std::string &name, uint32_t messagecount, uint32_t consumercount) {

channel.declareQueue(AMQP::exclusive
).onSuccess([](const std::string &name, uint32_t /* messagecount */, uint32_t /* consumercount */) {

// report the name of the temporary queue
std::cout << "declared queue " << name << std::endl;

// now we can close the connection
connection.close();

}).onError([](const char *message) {

// something went wrong creating the queue (or even before)
std::cerr << "declareQueue error: " << message << std::endl;
});

// run the handler
// a t the moment, one will need SIGINT to stop. In time, should add signal handling through boost API.
return service.run();
return context.run();
}

5 changes: 1 addition & 4 deletions include/amqpcpp/deferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Deferred
// store pointer
_next = deferred;
}

/**
* Remove this object from the chain of deferreds
*/
Expand Down Expand Up @@ -282,9 +282,6 @@ class Deferred
* or fails. This function will be called
* either way.
*
* In the case of success, the provided
* error parameter will be an empty string.
*
* Only one callback can be registered at at time.
* Successive calls to this function will clear
* callbacks registered before.
Expand Down
Loading