簡體   English   中英

使用C ++將圖像寫入RabbitMQ隊列

[英]Using C++ to write an image to a RabbitMQ queue

我正在使用SimpleAmqpClient ,它是一個與RabbitMQ代理一起使用的C ++庫。 我可以發送和接收字符串,即“ hello world”。 這是執行此操作的程序

#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);
}

它調用這些函數中的第一個使用字符串。

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);
}

我想將JPEG圖像寫入不是字符串的隊列。

有人可以評論我該怎么做嗎?

您有兩個選擇。

  1. 將圖像字節序列化為Base-64編碼的字符串

  2. 直接將圖像發布為字節數組。

應該注意的是,RabbitMQ在處理非常小的(<25kB)消息時效果最佳。 如果您的圖像大小很大(例如大於此大小),則如果消息量很大,則代理可能會出現性能問題。 在這種情況下,最好為不涉及消息代理的大文件設置備用流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM