-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export send batch messages api in c style
- Loading branch information
Showing
5 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "CBatchMessage.h" | ||
#include "CCommon.h" | ||
#include "CMessage.h" | ||
#include "CProducer.h" | ||
#include "CSendResult.h" | ||
|
||
void StartSendMessage(CProducer* producer) { | ||
int i = 0; | ||
int ret_code = 0; | ||
char body[128]; | ||
CBatchMessage* batchMessage = CreateBatchMessage("T_TestTopic"); | ||
|
||
for (i = 0; i < 10; i++) { | ||
CMessage* msg = CreateMessage("T_TestTopic"); | ||
SetMessageTags(msg, "Test_Tag"); | ||
SetMessageKeys(msg, "Test_Keys"); | ||
memset(body, 0, sizeof(body)); | ||
snprintf(body, sizeof(body), "new message body, index %d", i); | ||
SetMessageBody(msg, body); | ||
AddMessage(batchMessage, msg); | ||
} | ||
CSendResult result; | ||
int ok = SendBatchMessage(producer, batchMessage, &result); | ||
printf("SendBatchMessage is %s .....\n", ok == 0 ? "Success" : ok == 11 ? "FAILED" : " It is null value"); | ||
DestroyBatchMessage(batchMessage); | ||
} | ||
|
||
void CreateProducerAndStartSendMessage() { | ||
printf("Producer Initializing.....\n"); | ||
CProducer* producer = CreateProducer("Group_producer"); | ||
SetProducerNameServerAddress(producer, "127.0.0.1:9876"); | ||
StartProducer(producer); | ||
printf("Producer start.....\n"); | ||
StartSendMessage(producer); | ||
ShutdownProducer(producer); | ||
DestroyProducer(producer); | ||
printf("Producer Shutdown!\n"); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
printf("Send Batch.....\n"); | ||
CreateProducerAndStartSendMessage(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __C_BATCHMESSAGE_H__ | ||
#define __C_BATCHMESSAGE_H__ | ||
#include "CCommon.h" | ||
#include "CMessage.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct CBatchMessage CBatchMessage; | ||
|
||
ROCKETMQCLIENT_API CBatchMessage* CreateBatchMessage(); | ||
ROCKETMQCLIENT_API int AddMessage(CBatchMessage* batchMsg, CMessage* msg); | ||
ROCKETMQCLIENT_API int DestroyBatchMessage(CBatchMessage* batchMsg); | ||
|
||
#ifdef __cplusplus | ||
}; | ||
#endif | ||
#endif //__C_BATCHMESSAGE_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <vector> | ||
|
||
#include "CBatchMessage.h" | ||
#include "CCommon.h" | ||
#include "CMessage.h" | ||
#include "MQMessage.h" | ||
|
||
using std::vector; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
using namespace rocketmq; | ||
|
||
CBatchMessage* CreateBatchMessage() { | ||
vector<MQMessage>* msgs = new vector<MQMessage>(); | ||
return (CBatchMessage*)msgs; | ||
} | ||
|
||
int AddMessage(CBatchMessage* batchMsg, CMessage* msg) { | ||
if (msg == NULL) { | ||
return NULL_POINTER; | ||
} | ||
if (batchMsg == NULL) { | ||
return NULL_POINTER; | ||
} | ||
MQMessage* message = (MQMessage*)msg; | ||
((vector<MQMessage>*)batchMsg)->push_back(*message); | ||
return OK; | ||
} | ||
int DestroyBatchMessage(CBatchMessage* batchMsg) { | ||
if (batchMsg == NULL) { | ||
return NULL_POINTER; | ||
} | ||
delete (vector<MQMessage>*)batchMsg; | ||
return OK; | ||
} | ||
|
||
#ifdef __cplusplus | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters