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
6 changes: 3 additions & 3 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
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