Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation issue when using AMQP::Reliable #538

Open
quidstone opened this issue Nov 22, 2024 · 0 comments
Open

Compilation issue when using AMQP::Reliable #538

quidstone opened this issue Nov 22, 2024 · 0 comments

Comments

@quidstone
Copy link

Describe the bug
I am trying to compile using the Reliable. But it is giving me compilation error. I am using 4.3.19 version on Ubuntu 22.

Expected behavior and actual behavior
A successful compilation. I have built the library with,

cmake -S ../ -B . -DAMQP-CPP_BUILD_SHARED=ON -DAMQP-CPP_LINUX_TCP=ON -DCMAKE_INSTALL_PREFIX=./installed/

It is giving me the following error:

libboostasio.cpp: In function ‘int main()’:
libboostasio.cpp:56:11: error: ‘Reliable’ is not a member of ‘AMQP’
   56 |     AMQP::Reliable reliable(&channel);
      |           ^~~~~~~~
libboostasio.cpp:58:5: error: ‘reliable’ was not declared in this scope
   58 |     reliable.publish("", QNAME, "my first message")

Sample code

I am using the libboostasio.cpp example.

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


#include <amqpcpp.h>
#include <amqpcpp/libboostasio.h>

#include <iostream>

#define QNAME "test-Q"

/**
 *  Main program
 *  @return int
 */
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);

    // handler for libev
    AMQP::LibBoostAsioHandler handler(service);
    
    // make a connection
    AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://test:nopass@localhost/"));
    
    // we need a channel too
    AMQP::TcpChannel channel(&connection);
    
    // create a temporary queue
    channel
    .declareQueue(QNAME)
    .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();
    });

    AMQP::Reliable reliable(channel);
    // publish a message via the reliable-channel
    reliable.publish("", QNAME, "my first message")
    .onAck([]() {

    	// the message has been acknowledged by RabbitMQ (in your application
        // code you can now safely discard the message as it has been picked up)
	std::cout << "onSuccess: " << std::endl;

    }).onNack([]() {

    	// the message has _explicitly_ been nack'ed by RabbitMQ (in your application
    	// code you probably want to log or handle this to avoid data-loss)
	std::cout << "onNack: " << std::endl;

    }).onLost([]() {

    	// because the implementation for onNack() and onError() will be the same
    	// in many applications, you can also choose to install a onLost() handler,
    	// which is called when the message has either been nack'ed, or lost.
	std::cout << "onLost: " << std::endl;

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

    	// a channel-error occurred before any ack or nack was received, and the 
    	// message is probably lost (which you might want to handle)
	std::cout << "onError: " << 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant