first commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.idea/
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "libs/rmqcpp"]
|
||||||
|
path = libs/rmqcpp
|
||||||
|
url = https://github.com/bloomberg/rmqcpp.git
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
project(cpp_worker_dubla3)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
|
add_executable(cpp_worker_dubla3
|
||||||
|
main.cpp
|
||||||
|
src/rmq/ConnectionHandler.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(cpp_worker_dubla3 PRIVATE
|
||||||
|
/usr/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_directories(cpp_worker_dubla3 PRIVATE
|
||||||
|
/usr/lib
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(cpp_worker_dubla3 PRIVATE
|
||||||
|
amqpcpp
|
||||||
|
pthread
|
||||||
|
dl
|
||||||
|
uv
|
||||||
|
ssl
|
||||||
|
)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include "src/rmq/ConnectionHandler.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <amqpcpp.h>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// access to the event loop
|
||||||
|
auto *loop = uv_default_loop();
|
||||||
|
|
||||||
|
// handler for libev
|
||||||
|
ConnectionHandler handler(loop);
|
||||||
|
|
||||||
|
// make a connection
|
||||||
|
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://proxmox:proxmox@mq.pseudot.org:5671"));
|
||||||
|
|
||||||
|
// we need a channel too
|
||||||
|
AMQP::TcpChannel channel(&connection);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
});
|
||||||
|
|
||||||
|
// run the loop
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
|
||||||
|
// done
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#include "ConnectionHandler.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void ConnectionHandler::onConnected(AMQP::TcpConnection *connection)
|
||||||
|
{
|
||||||
|
std::cout << "TCP CONNECTED\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConnectionHandler::onReady(AMQP::TcpConnection *connection)
|
||||||
|
{
|
||||||
|
std::cout << "AMQP READY\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConnectionHandler::onError(
|
||||||
|
AMQP::TcpConnection *connection,
|
||||||
|
const char *message)
|
||||||
|
{
|
||||||
|
std::cout << "ERROR: "
|
||||||
|
<< message
|
||||||
|
<< '\n';
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <uv.h>
|
||||||
|
#include <amqpcpp.h>
|
||||||
|
#include <amqpcpp/libuv.h>
|
||||||
|
|
||||||
|
class ConnectionHandler : public AMQP::LibUvHandler {
|
||||||
|
public:
|
||||||
|
ConnectionHandler(uv_loop_t *loop)
|
||||||
|
: AMQP::LibUvHandler(loop)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void onConnected(AMQP::TcpConnection *connection) override;
|
||||||
|
|
||||||
|
void onReady(AMQP::TcpConnection *connection) override;
|
||||||
|
|
||||||
|
void onError(AMQP::TcpConnection *connection, const char *message) override;
|
||||||
|
|
||||||
|
~ConnectionHandler() override = default;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user