【发布时间】:2017-01-23 11:27:08
【问题描述】:
我已经在我的 Linux 机器上安装了 rabbitmq-server。我已经安装了RABBIRMQ官网给出的AMQP-CPP客户端库。enter link description here
现在我想以生产者的身份连接到rabbitmq-server,并想在队列中发布一条消息。 我做了一个连接处理程序,主文件如下:
int main(int argc, char ** argv) {
const std:: string exchange = "my-exchange";
const std:: string routingKey = "my-routing-key";
const char* message = "HELLO WORLD";
MyTcpHandler myHandler;
// address of the server
cout << "TcpHandler object created.." << endl;
AMQP:: Address address("amqp://guest:guest@localhost:5672");
//("amqp://guest:guest@localhost/vhost");
cout << "address object created.." << endl;
// create a AMQP connection object
AMQP:: TcpConnection connection(& myHandler, address);
cout << "connection object created.." << endl;
// and create a channel
AMQP:: TcpChannel channel(& connection);
cout << "channel object created.." << endl;
// use the channel object to call the AMQP method you like
channel.declareExchange("my-exchange", AMQP:: fanout);
channel.declareQueue("my-queue");
channel.bindQueue("my-exchange", "my-queue", "my-routing-key");
cout << "before publish.." << endl;
// start a transaction
channel.startTransaction();
int pubVal = channel.publish(exchange, routingKey, message);
我无法连接到队列。也许我没有在 MyTcpHandler 类中正确实现“监视器”方法: 虚拟 void 监视器(AMQP::TcpConnection *connection,int fd,int flags) 有人可以帮忙吗?
【问题讨论】:
-
嗨,谁能帮帮我?请...
-
您遇到的错误是什么?
-
嗨@cantSleepNow 我无法将消息从生产者端发布到我的代理中的队列。即使我无法连接到经纪人。尽管我的制片人没有给出任何错误。我正在使用上面提到的 C++ 客户端。请帮帮我。我长期以来一直面临这个问题。提前致谢。