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

How to quit basicsumemessage when a quit signal coming ? #314

Open
tms2003 opened this issue Feb 23, 2023 · 0 comments
Open

How to quit basicsumemessage when a quit signal coming ? #314

tms2003 opened this issue Feb 23, 2023 · 0 comments

Comments

@tms2003
Copy link

tms2003 commented Feb 23, 2023

Hi,
I write a thread for processing rmq message.I use BaseConsumeMessage to waiting some message,my code like this:

AmqpClient::Channel::ptr_t channel = AmqpClient::Channel::Create(_serverUrl, _port, _userName, _password);

    

    channel->DeclareQueue(this->_rmq_queque, false, true, false, false);

    std::string consumer_tag = channel->BasicConsume(this->_rmq_queque, "");
    while (1)
    {
        std::cout << "[y] wait for the message" << std::endl;

        AmqpClient::Envelope::ptr_t envelope =
            channel->BasicConsumeMessage(consumer_tag);

        std::string buffer = envelope->Message()->Body();
       
        std::cout << "[y] receve " << buffer << std::endl;

  
       //quit the cyc when the quit var set true by main thread,
      //*******************  but ,it can't execute because waiting message
        if (quit)
        {

            cout << "amq cmd rec  thread over!" << endl;
            break;
        }
    }

    channel->BasicCancel(consumer_tag);

but ,I want to quit this thread when a signal send by main thread. but the BaseConsumeMessage blocking for waiting rmq message and can't processed any other code ,so,how can solve it ?

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