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

     1  ---
     2  title: Framework
     3  keywords: go-micro, framework
     4  tags: [go-micro, framework]
     5  sidebar: home_sidebar
     6  permalink: /framework
     7  summary: Go Micro is a framework for microservices development
     8  ---
     9  
    10  # Overview
    11  
    12  Go Micro provides the core requirements for distributed systems development including RPC and Event driven communication. 
    13  The micro philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly but everything can be easily swapped out.
    14  
    15  ## Features
    16  
    17  Go Micro abstracts away the details of distributed systems. Here are the main features.
    18  
    19  - **Service Discovery** - Automatic service registration and name resolution. Service discovery is at the core of micro service
    20  development. When service A needs to speak to service B it needs the location of that service. The default discovery mechanism is
    21  multicast DNS (mdns), a zeroconf system.
    22  
    23  - **Load Balancing** - Client side load balancing built on service discovery. Once we have the addresses of any number of instances
    24  of a service we now need a way to decide which node to route to. We use random hashed load balancing to provide even distribution
    25  across the services and retry a different node if there's a problem.
    26  
    27  - **Message Encoding** - Dynamic message encoding based on content-type. The client and server will use codecs along with content-type
    28  to seamlessly encode and decode Go types for you. Any variety of messages could be encoded and sent from different clients. The client
    29  and server handle this by default. This includes protobuf and json by default.
    30  
    31  - **Request/Response** - RPC based request/response with support for bidirectional streaming. We provide an abstraction for synchronous
    32  communication. A request made to a service will be automatically resolved, load balanced, dialled and streamed. The default
    33  transport is [gRPC](https://grpc.io/).
    34  
    35  - **Async Messaging** - PubSub is built in as a first class citizen for asynchronous communication and event driven architectures.
    36  Event notifications are a core pattern in micro service development. The default messaging system is an embedded [NATS](https://nats.io/)
    37  server.
    38  
    39  - **Pluggable Interfaces** - Go Micro makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces
    40  are pluggable and allows Go Micro to be runtime agnostic. You can plugin any underlying technology. Find plugins in
    41  [github.com/micro/go-plugins](https://github.com/micro/go-plugins).
    42  
    43  ## Getting started
    44  
    45  - [Dependencies](#dependencies)
    46  - [Installation](#installation)
    47  - [Writing a Service](#writing-a-service)
    48  
    49  ## Dependencies
    50  
    51  Go Micro makes use of protobuf by default. This is so we can code generate boilerplate code and also provide 
    52  an efficient wire format for transferring data back and forth between services.
    53  
    54  We also require some form of service discovery to resolve service names to their addresses along with 
    55  metadata and endpoint information. See below for more info.
    56  
    57  ### Protobuf
    58  
    59  You'll need to install protobuf to code generate API interfaces:
    60  
    61  - [protoc-gen-micro](https://github.com/tickoalcantara12/micro/tree/master/cmd/protoc-gen-micro)
    62  
    63  ### Discovery
    64  
    65  Service discovery is used to resolve service names to addresses. By default we provide a zeroconf discovery system 
    66  using multicast DNS. This comes built-in on most operating systems. If you need something more resilient and multi-host then use etcd.
    67  
    68  ### Etcd
    69  
    70  [Etcd](https://github.com/etcd-io/etcd) can be used as an alternative service discovery system.
    71  
    72  - Download and run [etcd](https://github.com/etcd-io/etcd)
    73  - Pass `--registry=etcd` to any command or the enviroment variable `MICRO_REGISTRY=etcd`
    74  
    75  ```
    76  MICRO_REGISTRY=etcd go run main.go
    77  ```
    78  
    79  Discovery is pluggable. Find plugins for consul, kubernetes, zookeeper and more in the [micro/go-plugins](https://github.com/micro/go-plugins) repo.
    80  
    81  ## Installation
    82  
    83  Go Micro is a framework for Go based development. You can easily get this with the go toolchain.
    84  
    85  
    86  Import go-micro in your service
    87  
    88  ```
    89  import "github.com/micro/go-micro/v2"
    90  ```
    91  
    92  We provide release tags and would recommend to stick with the latest stable releases. Making use of go modules will enable this.
    93  
    94  ```
    95  # enable go modules
    96  export GO111MODULE=on
    97  # initialise go modules in your app
    98  go mod init
    99  # now go get
   100  go get ./...
   101  ```
   102  
   103  ## Writing a service
   104  
   105  Go checkout the [hello world](helloworld.html) example to get started
   106