Я пытаюсь сделать простое консольное приложение для Windows. Я установил AMQP-CPP и включил библиотеку в свой проект Visual Studio. Моя задача - создать простую связь с сервером rabbitmq.
Основная функция:
#include <amqpcpp.h>
#include "rabbitmqModels.h"
int main(){
string msg = "hello world";
string queueName = "message_queue";
string exchangeName = "myexchange";
string routingKey = "hello";
Address address("amqp://guest:guest@localhost:15672");
MyConnectionHandler myHandler;
Connection connection(&myHandler, address);
Channel channel(&connection);
channel.declareQueue(queueName);
channel.declareExchange(exchangeName, direct).onSuccess([]();
channel.bindQueue(exchangeName, queueName, routingKey);
channel.publish(exchangeName, routingKey, msg, msg.size());
return 0;
}
, где код rabbitmqModels.h:
using namespace AMQP;
class MyConnectionHandler : public ConnectionHandler
{
private:
/**
* Method that is called by the AMQP library every time it has data
* available that should be sent to RabbitMQ.
* @param connection pointer to the main connection object
* @param data memory buffer with the data that should be sent to RabbitMQ
* @param size size of the buffer
*/
virtual void onData(Connection* connection, const char* data, size_t size)
{
// @todo
// Add your own implementation, for example by doing a call to the
// send() system call. But be aware that the send() call may not
// send all data at once, so you also need to take care of buffering
// the bytes that could not immediately be sent, and try to send
// them again when the socket becomes writable again
}
virtual void onReady(Connection* connection) override
{
// @todo
// add your own implementation, for example by creating a channel
// instance, and start publishing or consuming
std::cout << "Connection is established...\n";
}
virtual void onError(Connection* connection, const char* message)
{
// report error
std::cout << "Connection Error: " << message << std::endl;
}
virtual void onClosed(Connection* connection)
{
std::cout << "closed" << std::endl;
}
virtual void onConnected(Connection* connection)
{
std::cout << "connected" << std::endl;
}
};
Код создается без ошибок. Обратите внимание, что мой сервер rabbitmq работает на localhost: 15672, и я определил как очередь, так и ключ обмена / маршрутизации.
Дело в том, что я не вижу сообщений, поступающих в мою определенную очередь на сервере. Должен ли я использовать только TCPHandler? Я не могу найти любую реализацию TCPHandler для Windows. Можете ли вы предоставить какую-либо помощь? Заранее спасибо!