githublaohu commented on a change in pull request #65: Realization C asynSend URL: https://github.com/apache/rocketmq-client-cpp/pull/65#discussion_r247784936
########## File path: example/CAsyncProducer.c ########## @@ -0,0 +1,95 @@ +/* +* 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 "CProducer.h" +#include "CCommon.h" +#include "CMessage.h" +#include "CSendResult.h" + +#ifdef _WIN32 +#include <windows.h> +#else + +#include <unistd.h> +#include <memory.h> + +#endif + +void thread_sleep(unsigned milliseconds) { +#ifdef _WIN32 + Sleep(milliseconds); +#else + usleep(milliseconds * 1000); // takes microseconds +#endif +} + +void sendSuccessCallback(CSendResult result){ + printf("Msg Send ID:%s\n", result.msgId); +} + +void sendExceptionCallback(CMQException e){ + printf("asyn send exception error : %d\n" , e.error); + printf("asyn send exception msg : %s\n" , e.msg); + printf("asyn send exception file : %s\n" , e.file); + printf("asyn send exception line : %d\n" , e.line); +} + +void startSendMessage(CProducer *producer) { + int i = 0; + char DestMsg[256]; + CMessage *msg = CreateMessage("T_TestTopic"); + SetMessageTags(msg, "Test_Tag"); + SetMessageKeys(msg, "Test_Keys"); + CSendResult result; + for (i = 0; i < 10; i++) { + printf("send one message : %d\n", i); + memset(DestMsg, 0, sizeof(DestMsg)); + snprintf(DestMsg, 255, "New message body: index %d", i); Review comment: Already processed ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
