Я использую C ++ RabbitMQ клиент .Код ниже показывает, как отправить строку.
int main(int argc, char** argv)
{
//Setup stuff
string a="hello world";
boost::shared_ptr<SimplePublisher> pub=SimplePublisher::Create(channel, "wt");
pub->Publish(a);
}
Вот методы Publish()
:
#include "SimplePublisher.h"
void SimplePublisher::Publish(const std::string &message)
{
BasicMessage::ptr_t outgoing_message =
BasicMessage::Create(message);
outgoing_message->Body(message);
Publish(outgoing_message);
}
void SimplePublisher::Publish(const BasicMessage::ptr_t message)
{
m_channel->BasicPublish(m_publisherExchange, "", message);
}
Вызов метода Publish()
1 из 3 Create()
методов в классе BasicMessage
, как показано здесь.Пример hello world вызывает тот, у которого есть строковый аргумент Create(const std::string &body)
.
/**
* Create a new empty BasicMessage object
*/
static ptr_t Create() { return boost::make_shared<BasicMessage>(); }
/**
* Create a new BasicMessage object
* Creates a new BasicMessage object with a given body
* @param body the message body.
* @returns a new BasicMessage object
*/
static ptr_t Create(const std::string &body) {
return boost::make_shared<BasicMessage>(body);
}
/**
* Create a new BasicMessage object
* Creates a new BasicMessage object with a given body, properties
* @param body the message body. The message body is NOT duplicated.
* Passed in message body is deallocated when: body is set or message is
* destructed.
* @properties the amqp_basic_properties_t struct. Note this makes a deep
* copy of the properties struct
* @returns a new BasicMessage object
*/
static ptr_t Create(amqp_bytes_t_ &body,
amqp_basic_properties_t_ *properties) {
return boost::make_shared<BasicMessage>(body, properties);
}
Мой вопрос заключается в том, что я хочу отправить массив байтов, а не строку.Поэтому мне нужно позвонить Create(amqp_bytes_t_ &body, amqp_basic_properties_t_ *properties)
.
. Библиотека является оболочкой для RabbitMQ C AMQP .amqp_bytes_t_
и amqp_basic_properties_t_
являются структурами в этой библиотеке.
Может кто-нибудь продемонстрировать, как отправить байтовый массив в этом примере вместо Hello World?