#include "test_producer_consumer.h"
#include <nng/protocol/pubsub0/pub.h>
#include <thread>
#include <iostream>


int main()
{
    spdlog::set_level(spdlog::level::info);

    nng_socket pubSocket = NNG_SOCKET_INITIALIZER;

    if (int res = nng_pub0_open(&pubSocket))
        mnode_nng_fatal("nng_pub0_open", res);

    if (int res = nng_listen(pubSocket, "tcp://*:42777", nullptr, 0))
        mnode_nng_fatal("nng_listen tcp", res);

    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))
            mnode_nng_fatal("nng_msg_alloc", res);

        if (auto res = nng_sendmsg(pubSocket, msg, 0))
            mnode_nng_fatal("nng_sendmsg", res);
    }

    return 0;
}
