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

create BufferedProducer<std::string> producer globally #299

Open
barzan-hayati opened this issue Oct 23, 2022 · 0 comments
Open

create BufferedProducer<std::string> producer globally #299

barzan-hayati opened this issue Oct 23, 2022 · 0 comments

Comments

@barzan-hayati
Copy link

I want to define and create connection once. So I define these variables out of main

MessageBuilder *builder_appearance;
Configuration *config_appearance;
BufferedProducer<std::string> *buffered_producer_appearance;

In a function I set parameters to these objects:


int create_json_connection()
{
    int partition_value = -1;

    po::options_description options("Options");
    options.add_options()
            ("help,h",      "produce this help message")
            ("brokers,b",   po::value<string>(&brokers)->required(),
             "the kafka broker list")
            ("topic,t",     po::value<string>(&topic_name)->required(),
             "the topic in which to write to")
            ("partition,p", po::value<int>(&partition_value),
             "the partition to write into (unassigned if not provided)");

    po::variables_map vm;

    int argc = 5;
    const char* argv[argc];
    argv[0] = argv0.c_str();
    argv[1] = "-b";
    argv[2] = brokers.c_str();
    argv[3] = "-t";
    argv[4] = topic_name.c_str();

    try
    {
        po::store(po::command_line_parser(argc, argv).options(options).run(), vm);
        po::notify(vm);
    }
    catch (exception& ex)
    {
        cout << "\033[1;31m Error parsing options: \033[0m" << ex.what() << endl << endl;
        cout << options << endl;
        return 0;
    }
    builder_appearance->topic(topic_name);
    if (partition_value != -1)
    {
        builder_appearance->partition(partition_value);
    }

    config_appearance->set_default_topic_configuration({
                                                           { "metadata.broker.list", brokers },
                                                           { "statistics.interval.ms", 60000 }
                                                       });
}

Now I want to set Configuration to buffered_producer_appearance:

buffered_producer_appearance(*config_appearance);

But it gave me this error:


error: ‘buffered_producer_appearance’ cannot be used as a function
     buffered_producer_appearance(*config_appearance);
                                                    ^

So I should define producer1 as follows but it's not ideal for me:
BufferedProducer<std::string> producer1(*config_appearance);
How could I resolve this. Thanks in advance.

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