Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(producer) add exception mechanism for send message
  • Loading branch information
duhenglucky committed Oct 10, 2019
commit 37bc0bca0cbcbfd3868630f5bb194c95ee96aa4d
18 changes: 17 additions & 1 deletion src/PythonWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,17 @@ void PySendSuccessCallback(CSendResult result, CMessage *msg, void *pyCallback){

void PySendExceptionCallback(CMQException e, CMessage *msg, void *pyCallback){
PyThreadStateLock PyThreadLock; // ensure hold GIL, before call python callback
PyMQException exception;
PyCallback *callback = (PyCallback *)pyCallback;
boost::python::call<void>(callback->exceptionCallback, (void *) msg, e);
exception.error = e.error;
exception.line = e.line;
strncpy(exception.file, e.file, MAX_EXEPTION_FILE_LENGTH - 1);
exception.file[MAX_EXEPTION_FILE_LENGTH - 1] = 0;
strncpy(exception.msg, e.msg, MAX_EXEPTION_MSG_LENGTH - 1);
exception.msg[MAX_EXEPTION_MSG_LENGTH - 1] = 0;
strncpy(exception.type, e.type, MAX_EXEPTION_TYPE_LENGTH - 1);
exception.type[MAX_EXEPTION_TYPE_LENGTH - 1] = 0;
boost::python::call<void>(callback->exceptionCallback, (void *) msg, exception);
delete pyCallback;
}

Expand Down Expand Up @@ -333,6 +342,13 @@ BOOST_PYTHON_MODULE (librocketmqclientpython) {
.def("GetMsgId", &PySendResult::GetMsgId);
class_<PyMessageExt>("CMessageExt");

class_<PyMQException>("MQException")
.def_readonly("error", &PyMQException::error, "error")
.def_readonly("line", &PyMQException::line, "line")
.def("GetFile", &PyMQException::GetFile)
.def("GetMsg", &PyMQException::GetMsg)
.def("GetType", &PyMQException::GetType);

//For Message
def("CreateMessage", PyCreateMessage, return_value_policy<return_opaque_pointer>());
def("DestroyMessage", PyDestroyMessage);
Expand Down
19 changes: 19 additions & 0 deletions src/PythonWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ typedef struct _PySendResult_ {
}
} PySendResult;

typedef struct _PyMQException_ {
int error;
int line;
char file[MAX_EXEPTION_FILE_LENGTH];
char msg[MAX_EXEPTION_MSG_LENGTH];
char type[MAX_EXEPTION_TYPE_LENGTH];

const char *GetFile() {
return (const char *) file;
}
const char *GetMsg() {
return (const char *) msg;
}
const char *GetType() {
return (const char *) type;
}
} PyMQException;


typedef struct _PyMessageExt_ {
CMessageExt *pMessageExt;
} PyMessageExt;
Expand Down