You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by vo...@apache.org on 2019/10/12 03:51:13 UTC
[rocketmq-client-cpp] branch master updated: Polish the examples
This is an automated email from the ASF dual-hosted git repository.
vongosling pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new 25c1bc4 Polish the examples
new 6bf50cd Merge branch 'master' of github.com:apache/rocketmq-client-cpp
25c1bc4 is described below
commit 25c1bc4edfdc82464928a0e51877482d9d8a5d30
Author: vongosling <vo...@apache.org>
AuthorDate: Sat Oct 12 11:49:07 2019 +0800
Polish the examples
---
example/AsyncPushConsumer.cpp | 2 +-
example/Producer.c | 23 +++++++++++++++--------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/example/AsyncPushConsumer.cpp b/example/AsyncPushConsumer.cpp
index 9f0a955..414f967 100644
--- a/example/AsyncPushConsumer.cpp
+++ b/example/AsyncPushConsumer.cpp
@@ -108,4 +108,4 @@ int main(int argc, char* argv[]) {
producer.shutdown();
consumer.shutdown();
return 0;
-}
+}
\ No newline at end of file
diff --git a/example/Producer.c b/example/Producer.c
index d2ec426..7965df6 100644
--- a/example/Producer.c
+++ b/example/Producer.c
@@ -27,11 +27,11 @@
#include <memory.h>
#endif
-void thread_sleep(unsigned milliseconds) {
+void thread_sleep(unsigned int milliseconds) {
#ifdef _WIN32
Sleep(milliseconds);
#else
- usleep(milliseconds * 1000); // takes microseconds
+ usleep(milliseconds * 1000); // suspend execution for microsecond intervals
#endif
}
@@ -42,26 +42,33 @@ void StartSendMessage(CProducer* producer) {
SetMessageTags(msg, "Test_Tag");
SetMessageKeys(msg, "Test_Keys");
CSendResult result;
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < 3; i++) {
memset(body, 0, sizeof(body));
snprintf(body, sizeof(body), "new message body, index %d", i);
SetMessageBody(msg, body);
- SendMessageSync(producer, msg, &result);
- printf("send message[%d] result status:%d, msgId:%s\n", i, (int)result.sendStatus, result.msgId);
+ int status = SendMessageSync(producer, msg, &result);
+ if(status == OK){
+ printf("send message[%d] result status:%d, msgId:%s\n", i, (int)result.sendStatus, result.msgId);
+ }else{
+ printf("send message[%d] failed !\n",i);
+ }
thread_sleep(1000);
}
DestroyMessage(msg);
}
int main(int argc, char* argv[]) {
- printf("Producer Initializing.....\n");
+ printf("Producer initializing ...\n");
CProducer* producer = CreateProducer("Group_producer");
SetProducerNameServerAddress(producer, "127.0.0.1:9876");
StartProducer(producer);
- printf("Producer start.....\n");
+
+ printf("Producer starting ...\n");
StartSendMessage(producer);
+
+ printf("Producer stopping !\n");
ShutdownProducer(producer);
DestroyProducer(producer);
- printf("Producer Shutdown!\n");
+
return 0;
}