lichao
2021-04-01 d26327b3cde043a9470dcd7fea8e704ea517fdae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * =====================================================================================
 *
 *       Filename:  reqrep_center.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年04月01日 14时09分13秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef REQREP_CENTER_US3RBM60
#define REQREP_CENTER_US3RBM60
 
#include "defs.h"
#include "socket.h"
#include <chrono>
#include <mutex>
#include <set>
 
class ReqRepCenter
{
    class Socket : public ShmSocket
    {
    public:
        Socket(ShmSocket::Shm &shm) :
            ShmSocket(shm, &kBHTopicReqRepCenter, 1000) {}
        using ShmSocket::shm;
    };
    Socket socket_;
    ShmSocket::Shm &shm() { return socket_.shm(); }
    struct ProcInfo {
        std::string proc_id_; // unique name
        std::string server_mqid_;
        std::string ext_info_; // maybe json.
        uint64_t timestamp_ = 0;
    };
 
    typedef std::string Dests;
 
    std::mutex mutex_;
    std::unordered_map<std::string, Dests> topic_mq_;
    std::unordered_map<std::string, ProcInfo> procs_;
 
public:
    ReqRepCenter(ShmSocket::Shm &shm) :
        socket_(shm) {}
    ReqRepCenter() :
        ReqRepCenter(BHomeShm()) {}
    ~ReqRepCenter() { Stop(); }
    bool Start(const int nworker = 2);
    bool Stop() { return socket_.Stop(); }
};
 
#endif // end of include guard: REQREP_CENTER_US3RBM60