-
Notifications
You must be signed in to change notification settings - Fork 167
Realization C asynSend #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
} | ||
DefaultMQProducer *defaultMQProducer = (DefaultMQProducer *) producer; | ||
MQMessage *message = (MQMessage *) msg; | ||
CSendCallback* cSendCallback = new CSendCallback(cSendSuccessCallback , cSendExceptionCallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cSendCallback
should be deleted after send
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See MQClientAPIImpl::sendMessageAsync and AsyncCallbackWrap::operationComplete(90 line),and AsyncCallbackWrap::onException()[ 117 line]
include/CMQException.h
Outdated
typedef struct _CMQException_{ | ||
int error; | ||
int line; | ||
char file[MAX_MESSAGE_ID_LENGTH]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use the same macro MAX_MESSAGE_ID_LENGTH to different member here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
|
||
//typedef struct _CProducer_ _CProducer; | ||
typedef struct CProducer CProducer; | ||
typedef int(*QueueSelectorCallback)(int size, CMessage *msg, void *arg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need the parameter size, what's it function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QueueSelectorCallback is not asyn send callback function
include/MQClientException.h
Outdated
|
||
virtual const char* GetType() const throw() { return m_type.c_str(); } | ||
|
||
int GetLine() const throw(){ return m_line;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there will no exception for GetLine and GetFile, so need delete throw() for them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
src/extern/CProducer.cpp
Outdated
exception.error = e.GetError(); | ||
exception.line = e.GetLine(); | ||
strncpy(exception.msg, e.what(), MAX_MESSAGE_ID_LENGTH - 1); | ||
strncpy(exception.file, e.GetFile(), MAX_MESSAGE_ID_LENGTH - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong alignment, format them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
cout << "send Exception\n"; | ||
} | ||
public: | ||
virtual void onException(MQException& e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please format the alignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
src/extern/CProducer.cpp
Outdated
} | ||
virtual ~CSendCallback(){} | ||
virtual void onSuccess(SendResult& sendResult) { | ||
cout << "send onSuccess\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove stdout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@githublaohu Could you please check this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks , Already processed
|
||
#include <string.h> | ||
#include "RocketMQClient.h" | ||
#include "CCommon.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why include C type head file here? it is better to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
src/extern/CProducer.cpp
Outdated
try { | ||
defaultMQProducer->send(*message ,cSendCallback); | ||
} catch (exception &e) { | ||
return PRODUCER_SEND_ONEWAY_FAILED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error code is not right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@githublaohu it is better to define a new error code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
int line; | ||
char file[MAX_EXEPTION_CHAR_LENGTH]; | ||
char msg[MAX_EXEPTION_CHAR_LENGTH]; | ||
char type[MAX_EXEPTION_CHAR_LENGTH]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is better to define the MACRO separately, and the length of msg maybe bigger than 256, IMO, maybe 512 is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
example/CAsyncProducer.c
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use sizeof(DestMsg) instead of 255.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DestMsg chang to body? variable need keep the same style, that is first word for variable with lowercase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already processed
No description provided.