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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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
42 changes: 26 additions & 16 deletions examples/libboostasio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
*
* @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 libboostasio.cpp -o boost_test -lpthread -ldl -lboost_system -lamqpcpp
*/

/**
* 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 <amqpcpp.h>
Expand All @@ -27,30 +26,41 @@ 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;

// 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([]() {
std::cout << "channel ready" << std::endl;
});
channel.onError([](const char *message) {
std::cout << "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) {

// 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();
// at the moment, one will need SIGINT to stop. In time, should add signal handling through boost API.
return context.run();
}

Loading