Link Search Menu Expand Document

Using Micro

Micro is an open source platform for API driven services development.

Learn Micro

To learn about Micro head to the open source website


The core services available to you are

  • Authentication
  • Configuration Management
  • Event Streaming
  • gRPC Communication
  • Key Value Storage
  • PubSub Messaging
  • Service Discovery
  • Runtime Management

We’ll walk through these in more depth in the Concepts section but basically its the OSS Micro v3 provided to you with highly available distributed systems beneath the covers.

Creating a Service

Services are created using the Go framework provided by Micro. They make use of gRPC and protobuf at the core and provide a simpler set of abstractions to build on.

Here’s an example. If you want further info see the helloworld example.

Services are defined using protobuf

syntax = "proto3";

package helloworld;

service Helloworld {
	rpc Call(Request) returns (Response) {}

message Request {
	string name = 1;

message Response {
	string msg = 1;

They’re then code generated using protoc and implemented using Micro

package main

import (
	pb ""

type Helloworld struct{}

// Call is a single request handler called via client.Call or the generated client code
func (h *Helloworld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
	logger.Info("Received Helloworld.Call request")
	rsp.Msg = "Hello " + req.Name
	return nil

func main() {
	// Create service
	srv := service.New(

	// Register Handler

	// Run the service
	if err := srv.Run(); err != nil {

Calling Services

To use the services peak into the service directory on GitHub. Micro pre-initialises all the services for you so that all you have to do is import the package and call public functions made available to you.

Example. Lets make use of calling a service.

import (

	pb ""

req := client.NewRequest("helloworld", "Helloworld.Call", &pb.Request{Name: "Alice"})
rsp := new(pb.Response)
err := client.Call(context.Background(), req, &rsp)

If you want to use code generation

hw := pb.NewHelloworldService("helloworld", client.DefaultClient)
rsp, err := hw.Call(context.Background(), &pb.Request{Name: "Alice"})

Publish/Subscribe to Events

What about say publishing events?

import ""

events.Publish("event-topic", map[string]string{"foo": "bar"})

And on the subscribe side

eventChan, err := events.Subscribe("event-topic")

Storing and Retrieving Data

import (
	// we're fixing this
	kv ""

// write the record
	Key: "foo",
	Value: []byte(`Bar`),

// read the record
rec, err := store.Read("foo")

// delete the record

Further Documentation

To learn more about Micro head to the open source website

Copyright © 2020 Micro Services, Inc.