Go-micro server, Client simple example

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Introduction to Micro

Micro is a microservice toolkit. Its purpose are to simplify distributed systems Development.github address
Go Micro is a pluggable RPC framework for microservices. It is part of the Micro Toolkit. GitHub Address

Use Go-micro to easily build a server

  1. Installing and running Consul,consul is a service discovery software. Micro relies on the service discovery mechanism
    Installation:
    Consul is the default registry/discovery for Go-micro apps. It ' s however pluggable.https://www.consul.io/intro/getting-started/install.html
    Run:

    consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul
  2. Download my sample Rep
    Gomicrotest
    Note: There are some go dependencies that need to be git down, and then need to install PROTOBUF, specific ways to use Google

  3. Start the Micro Web
    Micro comes with a console that can view all services and interfaces
    http://localhost:8082/

    micro web
  4. Start the server
    Go to catalogue Server/test

    go run main.go

    Interface Mymicro--Testuser.getuser can select a service in Micro Web Http://localhost:8082/query after successful startup
    Click Execute directly to see the output proves the service is working.

  5. Start Client
    Enter Directory Client

    go run main.go

    You can see the output to prove that the client connection is OK

  6. Postman Test
    You can open the check on the Micro Web page and then get the RPC connection under Network and copy as Curl
    as follows:

      Curl ' http://local Host:8082/rpc '-h ' pragma:no-cache '-h ' origin:http://localhost:8082 '-h ' accept-encoding:gzip, deflate, BR '-H ' Accept -language:zh-cn,zh;q=0.8,en;q=0.6,zh-tw;q=0.4 '-H ' user-agent:mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) applewebkit/537.36 (khtml, like Gecko) chrome/55.0.2883.95 safari/537.36 '-H ' content-type:applic Ation/json '-h ' Accept: */* '-h ' cache-control:no-cache '-h ' referer:http://localhost:8082/query '-h ' connection:keep-a Live '--data-binary ' {"Service": "Mymicro", "Method": "Testuser.getuser", "request": {}} '--compressed  

    Postman Use the Post method to set the following parameters for access
    Address: Http://localhost:8082/rpc
    Headers:content-type:application/json
    body:{" Service ":" Mymicro "," Method ":" Testuser.getuser "," request ": {}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.