rocket consumer producer 示例代码

consumer:
#include <unistd.h>
#include <stdlib.h>
#include
#include
#include “rocketmq/CPushConsumer.h”
#include “rocketmq/CMessageExt.h”

using namespace std;

// consume message
int doConsumeMessage(struct CPushConsumer *consumer,
CMessageExt *msgExt)
{
GetMessageTopic(msgExt) //top_id
GetMessageTags(msgExt) //tag_id
GetMessageKeys(msgExt) //tag_key
GetMessageBody(msgExt) // 接收到的信息
return E_CONSUME_SUCCESS;
}

int main(int argc, char argv[])
{
cout << “Push consumer Initializing…” << endl;
// create push consumer and set some values for it
CPushConsumer consumer =
CreatePushConsumer(“Group_Consumer_Test”);
SetPushConsumerNameServerAddress(consumer, “192.168.2.217:9876”);
Subscribe(consumer, “Test_Topic”, "
");
// register message callback
RegisterMessageCallback(consumer, doConsumeMessage);
// start push consumer
StartPushConsumer(consumer);
cout << “Push consumer start, and listening message within 1min…” << endl;
for (int i = 0; i < 6; i++)
{
cout << "Already Running: " << (i * 10) << “S” << endl;
sleep(10000000);
}
// shutdown push consumer
ShutdownPushConsumer(consumer);
// destroy push consumer
DestroyPushConsumer(consumer);
cout << “PushConsumer Shutdown!” << endl;
return 0;
}
producer:
/

  • Description: Simple Producer demo
    */

#include <unistd.h>
#include <stdlib.h>
#include
#include
#include “rocketmq/CProducer.h”
#include “rocketmq/CMessage.h”
#include “rocketmq/CSendResult.h”

using namespace std;

// send message
void StartSendMessage(CProducer *producer)
{
CSendResult result;
// create message and set some values for it
CMessage *msg = CreateMessage(“Test_Topic”);
SetMessageTags(msg, “Test_Tag”);
SetMessageKeys(msg, “Test_Keys”);
// construct different body
string strMessageBody = “http://lexue-play.chatopera.com/live/ssss.flv”;
SetMessageBody(msg, strMessageBody.c_str());
// send message
SendMessageSync(producer, msg, &result);
cout << “send message[” << “], result status:” << (int)result.sendStatus << “, msgBody:” << strMessageBody << endl;
// destroy message
DestroyMessage(msg);
}
int main()
{
cout << “Producer Initializing…” << endl;
// create producer and set some values for it
CProducer *producer = CreateProducer(“avtr-producer”);
SetProducerNameServerAddress(producer, “192.168.2.217:9876”);
// start producer
StartProducer(producer);
cout << “Producer start…” << endl;
// send message
StartSendMessage(producer);
// shutdown producer
ShutdownProducer(producer);
// destroy producer
DestroyProducer(producer);
cout << “Producer Shutdown!” << endl;
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值