Reputation: 1711
I'm using SimpleAmqpClient which is a C++ library to use with a RabbitMQ broker. I can send and receive string i.e. "hello world". Here is the program that does that.
#include <stdlib.h>
#include <stdio.h>
#include <SimpleAmqpClient/SimpleAmqpClient.h>
#include <iostream>
#include "SimplePublisher.h"
using namespace AmqpClient;
using namespace std;
int main()
{
char *szBroker = getenv("AMQP_BROKER");
Channel::ptr_t channel;
if (szBroker != NULL)
channel = Channel::Create(szBroker);
else
channel = Channel::Create("192.168.66.1", 5672);
string a="hello world";
// SimplePublisher pub(channel);
boost::shared_ptr<SimplePublisher> pub=SimplePublisher::Create(channel, "wt");
pub->Publish(a);
}
It calls the first one of these functions which takes a string.
void SimplePublisher::Publish(const std::string &message)
{
BasicMessage::ptr_t outgoing_message = BasicMessage::Create();
outgoing_message->Body(message);
Publish(outgoing_message);
}
void SimplePublisher::Publish(const BasicMessage::ptr_t message)
{
m_channel->BasicPublish(m_publisherExchange, "", message);
}
I want to write a JPEG image to the queue which is not a string.
Could anybody comment on how I would do this?
Upvotes: 1
Views: 1486
Reputation: 16177
You have two options.
Serialize the image bytes to a Base-64 encoded string
Publish the image as a byte array directly.
It should be noted that RabbitMQ works best when operating on very small (<25kB) messages. If your images are of any considerable size (e.g. any larger than this), then you may have performance issues with the broker if your volume of messages is large. In that case, it would be best to set up an alternate stream for large files NOT involving the message broker.
Upvotes: 2