SimpleAmqpClient – I can’t see Messages on RabbitMQ web interface

  amqp, c++, client, queue, rabbitmq

i can’t see the message on RabbitMq localhost.
There is a connection and i also can see the Queue, but i cant receive Messages on localhost.

After i am disconnected, the Queue is deleted.

Here the code:

If i try to run only "dosend", i get the information "message sent" but if i click on getmessage (on localhost) i get the error –> 405 RESOURCE_LOCKED or the Queue is empty.

What i want is as follow:

  1. If i only run doSend: To send Message to a queue (my_queue), the Queue should not be deleted after i disconnected. And i should see the Message, when i click on get message in RabbitMQ Web platform.

  2. If i run doReceive: i want to see the Message in Queue (my_queue) if there is a Message sended by doSend or if i publish a message on rabbitMQ web platform.

     #include <iostream>
     #include <thread>
    
     #include <windows.h>
    
     #include <SimpleAmqpClient/SimpleAmqpClient.h>
    
     //amqp[s]://[username[:password]@]host[:port]/[vhost]
     const std::string CONNECTION_URI = "amqp://guest:[email protected]:5672";
     const std::string EXCHANGE = "my_exchange";
     const std::string QUEUE = "my_queue";
    
     void doSend()
     {
         std::cout << "Connecting to send" << std::endl;
         AmqpClient::Channel::ptr_t channel;
         try
         {
             //Open channel and declare exchange
             channel = AmqpClient::Channel::Open(AmqpClient::Channel::OpenOpts::FromUri(CONNECTION_URI));
             channel->DeclareExchange(EXCHANGE);
         }
         catch (const std::exception& ex)
         {
             std::cout << "Failed to start send: " << ex.what() << std::endl;
         }
    
         //Send messages
         std::cout << "Starting to send" << std::endl;
         size_t cnt = 0;
         while (true)
         {
             try
             {
                 AmqpClient::BasicMessage::ptr_t outMessage = AmqpClient::BasicMessage::Create();
                 outMessage->Body("Hello world " + std::to_string(cnt++));
                 channel->BasicPublish(EXCHANGE, "", outMessage);
                 std::cout << "Message sent" << std::endl;
             }
             catch (const std::exception& ex)
             {
                 std::cout << "Failed to send: " << ex.what() << std::endl;
             }
             Sleep(1000);
         }
     }
    
     void doReceive()
     {
         std::cout << "Connecting to receive" << std::endl;
         AmqpClient::Channel::ptr_t channel;
         std::string consumerTag;
         try
         {
             //Open channel, declare, bind and consume queue
             channel = AmqpClient::Channel::Open(AmqpClient::Channel::OpenOpts::FromUri(CONNECTION_URI));
             channel->DeclareQueue(QUEUE);
             channel->BindQueue(QUEUE, EXCHANGE);
             consumerTag = channel->BasicConsume(QUEUE, "");
         }
         catch (const std::exception& ex)
         {
             std::cout << "Failed to start receive: " << ex.what() << std::endl;
             return;
         }
    
         //Receive messages
         std::cout << "Starting to receive" << std::endl;
         while (true)
         {
             try
             {
                 AmqpClient::Envelope::ptr_t envelope = channel->BasicConsumeMessage(consumerTag);
                 AmqpClient::BasicMessage::ptr_t inMessage = envelope->Message();
                 std::cout << "Received message (" << inMessage->MessageId() << "): " << inMessage->Body() << std::endl;
             }
             catch (const std::exception& ex)
             {
                 std::cout << "Failed to receive: " << ex.what() << std::endl;
             }
         }
     }
    
     int main()
     {
         std::thread sendThread{ doSend };
         std::thread receiveThread{ doReceive };
         getchar();
     }
    

Source: Windows Questions C++

LEAVE A COMMENT