github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/docs/content/architect.md (about)

     1  ---
     2  title: "Architect"
     3  date: 2021-07-26T14:33:20+04:30
     4  draft: false
     5  weight: 50
     6  menu: "main"
     7  tags: ["wiki", "install", "guide"]
     8  categories: ["wiki"]
     9  
    10  weight: 30
    11  contentCopyright: MIT
    12  mathjax: true
    13  autoCollapseToc: false
    14  
    15  ---
    16  
    17  # Big Picture
    18  Rony provides facilities to implement clustered services quickly. When you write your service
    19  using Rony framework, you write the minimum amount of boiler-place code. Most of the code generated
    20  by Rony.
    21  
    22  {{< image src="/images/rony_overview.png" alt="Architect Diagram" position="center" style="border-radius: 8px;" >}}
    23  
    24  ## Components
    25  ### Edge
    26  The outermost layer of Rony is `edge.Server`. This is the only object which you need to
    27  access all the capabilities of Rony. Edge servers are identifies by their unique id (i.e., replica set)
    28  in a cluster. When you write your code you can do different actions depending on the replica-set of the
    29  current node, find other edge servers by their replica-set or their unique id.
    30  
    31  Edge servers are build of other sub-components. Gateway, Cluster, Tunnel and Store. In following we
    32  explain what is their responsibility of each component.
    33  
    34  #### 1. Gateway
    35  Gateway is the only component of the edge which MUST be setup. You cannot have an edge server without
    36  any gateway defined. Gateway manages the connection between `edge.Server` and external clients. Clients
    37  could talk to the gateway by `http`, `websocket` or both.
    38  
    39  #### 2. Cluster
    40  Cluster is an OPTIONAL component of the edge server. Cluster manages the cluster as its name spoiled.
    41  You set up cluster when initializing your edge server. Cluster communicates with each other by using gossip protocol.
    42  You can get information about the current node or any other node in the cluster by accessing `Cluster` components.
    43  
    44  #### 3. Tunnel
    45  Tunnel is an OPTIONAL component of the edge server. Tunnel provides end-to-end communication between edge server.
    46  Rony recommends to use `Tunnel` with the information collected from `Cluster` component.
    47  
    48  #### 4. Store
    49  Store is a REQUIRED component of the edge server. Store provides persistent key-value store. It is useful and could be
    50  used to by you to extend your ability to save structured data locally. It supports TTL on keys.
    51  
    52  ---
    53  
    54  ## Context
    55  
    56  Rony has three type contexts. They provide three layer of separation. `rony.Conn` `edge.DispatchCtx` and
    57  `edge.RequestCtx` are the layered contexts of Rony.
    58  ```
    59  |--- Conn ----------------------------------------|
    60  |   |--- DispatchCtx --------------------------|  |
    61  |   |   |--- RequestCtx -------------------|   |  |
    62  |   |   |--- RequestCtx -------------------|   |  |
    63  |   |   |   .                              |   |  |
    64  |   |   |   .                              |   |  |
    65  |   |------------------------------------------|  |
    66  |                                                 |
    67  |   |--- DispatchCtx --------------------------|  |
    68  |   |   |--- RequestCtx -------------------|   |  |
    69  |   |   |--- RequestCtx -------------------|   |  |
    70  |   |------------------------------------------|  |
    71  |                                                 |
    72  |                      .                          |
    73  |                      .                          |
    74  |-------------------------------------------------|
    75  ```
    76  
    77  ### 1. Conn
    78  Conn is the outermost context. It is created when a connection established between client and edge
    79  server. It is destroyed when the connection closed. Connections could be Persistent (i.e., websocket) or
    80  Non-Persistent (i.e., http).
    81  
    82  ### 2. DispatchCtx
    83  DispatchCtx is created when a message (i.e., MessageEnvelop or MessageContainer) received. It will exist until the last
    84  request executed. In other words if the received message was `MessageEnvelope` then DispatchCtx has only one `RequestCtx`
    85  and if the received message was `MessageContainer` then DispatchCtx has as many `RequestCtx` as the number of message envelops
    86  it contains.
    87  
    88  ### 3. RequestCtx
    89  RequestCtx is the latest context which actually is accessed by the developer. Each RPC handler has a reference to its
    90  `RequestCtx`. You have access to other sub-components such as Cluster, Tunnel and Store through the `RequestCtx`.
    91