2024-11-21 21:38:20 +01:00
|
|
|
#include "test_producer_consumer.h"
|
2024-05-07 14:59:06 +02:00
|
|
|
#include <nng/protocol/pubsub0/pub.h>
|
|
|
|
#include <thread>
|
|
|
|
#include <iostream>
|
|
|
|
|
2024-11-21 21:38:20 +01:00
|
|
|
|
|
|
|
int main()
|
2024-05-07 14:59:06 +02:00
|
|
|
{
|
|
|
|
spdlog::set_level(spdlog::level::info);
|
|
|
|
|
|
|
|
nng_socket pubSocket = NNG_SOCKET_INITIALIZER;
|
|
|
|
|
|
|
|
if (int res = nng_pub0_open(&pubSocket))
|
2024-12-07 17:36:59 +01:00
|
|
|
mnode_nng_fatal("nng_pub0_open", res);
|
2024-05-07 14:59:06 +02:00
|
|
|
|
|
|
|
if (int res = nng_listen(pubSocket, "tcp://*:42777", nullptr, 0))
|
2024-12-07 17:36:59 +01:00
|
|
|
mnode_nng_fatal("nng_listen tcp", res);
|
2024-05-07 14:59:06 +02:00
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
std::cout << "Enter size of pub message:";
|
|
|
|
size_t size = 0;
|
|
|
|
std::cin >> size;
|
|
|
|
|
|
|
|
fmt::print("Publishing message of size {}\n", size);
|
|
|
|
|
|
|
|
nng_msg *msg = nullptr;
|
|
|
|
|
|
|
|
if (int res = nng_msg_alloc(&msg, size))
|
2024-12-07 17:36:59 +01:00
|
|
|
mnode_nng_fatal("nng_msg_alloc", res);
|
2024-05-07 14:59:06 +02:00
|
|
|
|
|
|
|
if (auto res = nng_sendmsg(pubSocket, msg, 0))
|
2024-12-07 17:36:59 +01:00
|
|
|
mnode_nng_fatal("nng_sendmsg", res);
|
2024-05-07 14:59:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|