Github user lizhanhui commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq-externals/pull/11#discussion_r111867144
--- Diff: rocketmq-client4cpp/example/demo/AsyncProducer.cpp ---
@@ -0,0 +1,253 @@
+/**
+* Copyright (C) 2013 suwenkuang ,[email protected]
+*
+* Licensed 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 "Common.h"
+#include "SendCallback.h"
+#include "DefaultMQProducer.h"
+using namespace rmq;
+
+long long g_lastUpdateTime = 0;
+volatile long long g_cnt_total = 0;
+volatile long long g_cnt_last = 0;
+volatile long long g_cnt_succ = 0;
+volatile long long g_cnt_fail = 0;
+
+
+void Usage(const char* program)
+{
+ printf("Usage:%s ip:port [-g group] [-t topic] [-n count] [-s size]
[-w logpath]\n", program);
+ printf("\t -g group\n");
+ printf("\t -t topic\n");
+ printf("\t -n message count\n");
+ printf("\t -s message size \n");
+ printf("\t -w log path\n");
+}
+
+
+class SampleSendCallback : public SendCallback {
+public:
+ SampleSendCallback()
+ {
+ }
+
+ virtual ~SampleSendCallback()
+ {
+ }
+
+ int count()
+ {
+
+ long long now = MyUtil::getNowMs();
+ long long old = g_lastUpdateTime;
+ long long total = g_cnt_succ + g_cnt_fail;
+ if ((now - old) >= 1000)
+ {
+ if (__sync_bool_compare_and_swap(&g_lastUpdateTime, old, now))
+ {
+ long long time = now - old;
+ int tps = (int)((total - g_cnt_last) * 1.0 / time *
1000.0);
+ g_cnt_last = total;
+
+ MYDEBUG("[producer]succ: %lld, fail: %lld, TPS: %d\n",
+ g_cnt_succ, g_cnt_fail, tps);
+ }
+ }
+ }
+
+ void onSuccess(SendResult& sendResult)
+ {
+ int cnt = __sync_fetch_and_add(&g_cnt_total, 1);
+ __sync_fetch_and_add(&g_cnt_succ, 1);
+ MYLOG("[%d]|succ|%s\n", cnt, sendResult.toString().c_str());
+ }
+
+ void onException(MQException& e)
+ {
+ int cnt = __sync_fetch_and_add(&g_cnt_total, 1);
+ __sync_fetch_and_add(&g_cnt_fail, 1);
+
+ MYLOG("[%d]|fail|%s\n", cnt, e.what());
+ }
+};
+
+int main(int argc, char *argv[]) {
+ if (argc < 2)
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+
+ std::string namesrv = argv[1];
+ std::string group = "pg_test_group";
+ std::string topic = "topic_test";
+ int size = 32;
+ int count = 1000;
+
+ for (int i=2; i< argc; i++)
+ {
+ if (strcmp(argv[i],"-g")==0)
+ {
+ if (i+1 < argc)
+ {
+ group = argv[i+1];
+ i++;
+ }
+ else
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+ }
+ else if (strcmp(argv[i],"-t")==0)
+ {
+ if (i+1 < argc)
+ {
+ topic = argv[i+1];
+ i++;
+ }
+ else
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+ }
+ else if (strcmp(argv[i],"-n")==0)
+ {
+ if (i+1 < argc)
+ {
+ count = atoi(argv[i+1]);
+ i++;
+ }
+ else
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+ }
+ else if (strcmp(argv[i],"-s")==0)
+ {
+ if (i+1 < argc)
+ {
+ size = atoi(argv[i+1]);
+ i++;
+ }
+ else
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+ }
+ else if (strcmp(argv[i],"-w")==0)
+ {
+ if (i+1 < argc)
+ {
+ MyUtil::initLog(argv[i+1]);
+ i++;
+ }
+ else
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+ }
+ else
+ {
+ Usage(argv[0]);
+ return 0;
+ }
+ }
+
--- End diff --
IMO, it's also a good idea to create a few JIRA ticks, listing planned
tasks. This helps in that 1) we may track development progress; 2) new-joiner
may figure out what to do easier; 2) Developers won't repeat work on the same
issue.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---