github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/v2/framework/proxy.md (about)

     1  ---
     2  title: Service Proxy
     3  keywords: proxy
     4  tags: [proxy]
     5  sidebar: home_sidebar
     6  permalink: /proxy
     7  summary: The micro proxy is a service-to-service proxy.
     8  ---
     9  
    10  A service proxy is a server which acts as an intermediary for requests from one service to another.
    11  
    12  <img src="images/proxy.svg" />
    13  
    14  ## Overview
    15  
    16  The micro proxy provides a proxy implementation of the go-micro framework. This consolidates go-micro features into a single location which allows 
    17  offloading service discovery, load balancing, fault tolerance, plugins, wrappers, etc to the proxy itself. Rather than updating every Go Micro 
    18  app for infrastructure level concerns, its easier to put them in the proxy. It also allows any language to be integrated with a thin client 
    19  rather than having to implement all the features.
    20  
    21  ## Run Proxy
    22  
    23  Start the proxy
    24  
    25  ```shell
    26  micro proxy
    27  ```
    28  
    29  The server address is dynamic but can be configured as follows.
    30  
    31  ```
    32  MICRO_SERVER_ADDRESS=localhost:9090 micro proxy
    33  ```
    34  
    35  ## Proxy Services
    36  
    37  Now the proxy is running you can quite simply proxy requests through it.
    38  
    39  Start your go micro app like so
    40  
    41  ```
    42  MICRO_PROXY=go.micro.proxy go run main.go
    43  ```
    44  
    45  Your service will lookup the proxy in discovery then use it to route any requests. If multiple proxies exist it will balance 
    46  it's requests across them. It will also cache the proxy addresses locally.
    47  
    48  
    49  If you would rather send requests through a single proxy specify it's address like so.
    50  
    51  ```
    52  MICRO_PROXY=localhost:9090 go run main.go
    53  ```
    54  
    55  Ensure the proxy is running on the address specified.
    56  
    57  ```
    58  MICRO_SERVER_ADDRESS=localhost:9090 micro proxy
    59  ```
    60  
    61  ## Single Endpoint
    62  
    63  Use the proxy as a front proxy for a single endpoint
    64  
    65  ```
    66  MICRO_SERVER_NAME=helloworld \
    67  MICRO_PROXY_ENDPOINT=localhost:10001 \
    68  micro proxy
    69  ```
    70  
    71  All requests to helloworld will be sent to the backend at localhost:10001
    72