You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am evaluating a SimpleAmqpClient based cosumer example program (found from a previous issue).
The problem is that when I first send the message and then run the consumer, the consumer is not receiving anything. However, if I have the consumer running, then a new message sent to the exchange appears in the consumer.
following is the actual code:
#include<SimpleAmqpClient/SimpleAmqpClient.h>
#include<iostream>
#include<fstream>usingnamespaceAmqpClient;classConnectionData{
public:
std::string host;
int port;
std::string user;
std::string password;
std::string vHost;
std::string routingKey;
std::string exchange;
}theConnectionData;
voidmain()
{
theConnectionData.host = "127.0.0.1";
theConnectionData.port = 5672;
theConnectionData.user = "guest";
theConnectionData.password = "guest";
theConnectionData.vHost = "/";
theConnectionData.routingKey = "";
theConnectionData.exchange = "indexer";
std::ofstream file( "Log.txt" );
file << "Listener" << std::endl;
file << "\t" << "host: " << theConnectionData.host << std::endl;
file << "\t" << "port: " << theConnectionData.port << std::endl;
file << "\t" << "user: " << theConnectionData.user << std::endl;
file << "\t" << "password: " << theConnectionData.password << std::endl;
file << "\t" << "vHost: " << theConnectionData.vHost << std::endl;
file << "\t" << "routingKey: " << theConnectionData.routingKey << std::endl;
file.flush();
try
{
file << "AmqpClient::Channel::Create" << std::endl;
file.flush();
AmqpClient::Channel::ptr_t channelPtr = AmqpClient::Channel::Create();// theConnectionData.host, theConnectionData.port, theConnectionData.user, theConnectionData.password, theConnectionData.vHost);
file << "DeclareQueue" << std::endl;
file.flush();
std::string queueName = channelPtr->DeclareQueue("");
file << "\t" << "queue: " << queueName << std::endl;
file.flush();
file << "BindQueue" << std::endl;
file.flush();
channelPtr->BindQueue(queueName, theConnectionData.exchange, theConnectionData.routingKey );
file << "BasicConsume" << std::endl;
file.flush();
std::string consumer_tag = channelPtr->BasicConsume( queueName, "" );
file << "\t" << "tag: " << consumer_tag << std::endl;
file.flush();
/** **Fair dispatch** You might have noticed that the dispatching still doesn't work exactly as we want. For example in a situation with two workers, when all odd messages are heavy and even messages are light, one worker will be constantly busy and the other one will do hardly any work. Well, RabbitMQ doesn't know anything about that and will still dispatch messages evenly. This happens because RabbitMQ just dispatches a message when the message enters the queue. It doesn't look at the number of unacknowledged messages for a consumer. It just blindly dispatches every n-th message to the n-th consumer. In order to defeat that we can use the basicQos method with the prefetchCount = 1 setting. This tells RabbitMQ not to give more than one message to a worker at a time. Or, in other words, don't dispatch a new message to a worker until it has processed and acknowledged the previous one. Instead, it will dispatch it to the next worker that is not still busy. int prefetchCount = 1; channel.basicQos(prefetchCount);*///int prefetchCount = 1;//channelPtr->BasicQos(consumer_tag,prefetchCount);
file << "BasicConsumeMessage" << std::endl;
file.flush();
AmqpClient::Envelope::ptr_t envelopePtr = channelPtr->BasicConsumeMessage( consumer_tag );
file << "\t" << "body: " << envelopePtr->Message()->Body() << std::endl;
file.flush();
file << "BasicCancel" << std::endl;
file.flush();
channelPtr->BasicCancel( consumer_tag );
}
catch ( AmqpClient::AmqpException const& exception )
{
file << "Exception: " << typeid( exception ).name() << std::endl;
file << "\t" << "what: " << exception.what() << std::endl;
file << "\t" << "is_soft_error: " << exception.is_soft_error() << std::endl;
file << "\t" << "reply_code: " << exception.reply_code() << std::endl;
file << "\t" << "class_id: " << exception.class_id() << std::endl;
file << "\t" << "method_id: " << exception.method_id() << std::endl;
file << "\t" << "reply_text: " << exception.reply_text() << std::endl;
}
catch ( std::exceptionconst& exception )
{
file << "Exception: " << typeid( exception ).name() << std::endl;
file << "\t" << "what: " << exception.what() << std::endl;
}
catch ( ... )
{
file << "Exception: ..." << std::endl;
}
}
The text was updated successfully, but these errors were encountered:
When you publish a message to an exchange, the broker tries to route the message to a queue. If message can't be routed to a queue, the message is simply dropped.
In your case, when your consumer program isn't running, there is no queue declared to store the message, so the broker simply drops the message.
I am evaluating a SimpleAmqpClient based cosumer example program (found from a previous issue).
The problem is that when I first send the message and then run the consumer, the consumer is not receiving anything. However, if I have the consumer running, then a new message sent to the exchange appears in the consumer.
following is the actual code:
The text was updated successfully, but these errors were encountered: