| | |
| | | |
| | | } // namespace |
| | | |
| | | TopicNode::TopicNode(SharedMemory &shm) : |
| | | shm_(shm), state_(eStateUninited) |
| | | TopicNode::TopicNode(SharedMemory &shm, MQId ssn_id) : |
| | | shm_(shm), state_(eStateUninited), ssn_id_(ssn_id) |
| | | { |
| | | } |
| | | |
| | |
| | | reply_head.mutable_proc_id()->swap(out_proc_id); |
| | | return true; |
| | | } |
| | | } catch (...) { |
| | | } catch (std::exception &e) { |
| | | LOG_ERROR() << __func__ << " exception: " << e.what(); |
| | | SetLastError(eError, __func__ + std::string(" internal errer.")); |
| | | } |
| | | return false; |
| | |
| | | auto &sock = SockPub(); |
| | | BHMsgHead head(InitMsgHead(GetType(pub), proc_id(), ssn())); |
| | | AddRoute(head, sock); |
| | | head.set_topic(pub.topic()); |
| | | |
| | | if (timeout_ms == 0) { |
| | | return sock.Send(BusAddr(), head, pub); |
| | |
| | | |
| | | // subscribe |
| | | |
| | | bool TopicNode::Subscribe(MsgTopicList &topics, MsgCommonReply &reply_body, const int timeout_ms) |
| | | bool TopicNode::DoSubscribe(MsgTopicList &topics, const bool net, MsgCommonReply &reply_body, const int timeout_ms) |
| | | { |
| | | if (!IsOnline()) { |
| | | SetLastError(eNotRegistered, kErrMsgNotRegistered); |
| | |
| | | try { |
| | | auto &sock = SockSub(); |
| | | MsgSubscribe sub; |
| | | sub.set_network(net); |
| | | sub.mutable_topics()->Swap(&topics); |
| | | |
| | | BHMsgHead head(InitMsgHead(GetType(sub), proc_id(), ssn())); |
| | |
| | | reply.ParseBody(reply_body) && |
| | | IsSuccess(reply_body.errmsg().errcode()); |
| | | } |
| | | // TODO wait for result? |
| | | } catch (...) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | } |
| | | //TODO error msg. |
| | | if (head.type() == kMsgTypePublish) { |
| | | if (pub.ParseFromString(body)) { |
| | | head.mutable_proc_id()->swap(proc_id); |
| | | return true; |
| | | } |
| | | } |
| | | SetLastError(eError, "invalid subcribe msg received."); |
| | | return false; |
| | | } |