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