Micro on NATS - Microservices with Messaging
-
Upload
apcera -
Category
Technology
-
view
1.521 -
download
3
Transcript of Micro on NATS - Microservices with Messaging
Micro on NATSMicroservices with messaging
Who am I?
Asim Aslam
Working on Micro
Previously at Hailo
Before then Google
@chuhnk
asimaslam.com
What is Micro?
A microservice ecosystem
Simplifying building and managing distributed systems
What does that even mean?
Building OSS tools that make it easier to write and run micro service applications
Written in Go
100% Open Source
Micro A Microservice Toolkit
Go Micro - Pluggable RPC framework for writing microservices
API - API gateway. Translates HTTP to RPC. Path-to-Service resolution
Web - Dashboard and reverse proxy. Web apps as first class citizens
CLI - Command line interface. Straight forward. No frills.
Sidecar - HTTP interface with all the features of Go Micro
Bot - Hubot style bot for ChatOps. CLI Features. A bot? Really? Yea dude!
Go Micro RPC Framework
Registry - Service Discovery
Selector - Client side load balancer
Transport - Synchronous Communication
Broker - Asynchronous Communication
Codec - Message encoding
Client - RPC Client
Server - RPC Server
Why NATS?
Built for high performance and scale
Highly available - client and server side clustering
Extremely lightweight - written in Go, no persistence features
At most once delivery - fire and forget
Simple, focused and made for microservices
Written by Derek Collison, with two decades of experience building messaging systems
Micro on NATS NATS Plugins
Go-Micro has a pluggable architecture
Each feature written as a Go interface. Just implement the interface.
Integrate NATS using plugins for:
Registry - Service Discovery
Transport - Synchronous Communication
Broker - Asynchronous Communication
Transport Synchronous Communication
Handles request-response
Supports bidirectional streaming
Socket style semantics; Send(), Recv(), Close()
type Transport interface { Dial(addr string, opts ...DialOption) (Client, error) Listen(addr string, opts ...ListenOption) (Listener, error) String() string}
Transport
1. Server Listen - Subscribes to unique topic, wait for pseudo connections2. Client Dial - Subscribes to unique topic, publishes to Server with reply topic set3. Server Socket - Pseudo Socket created for every new “connection”4. Client Socket - Same as server. Send() - Publish, Recv() - Subscribed messages
Broker Asynchronous Communication
Publish and Subscribe mechanism
Includes notion of Topics and Channels (Queues)
Distribute messages between subscribers
type Broker interface { …. Connect() error Disconnect() error Publish(string, *Message, ...PublishOption) error Subscribe(string, Handler, ...SubscribeOption) (Subscriber, error) String() string}
Broker
1. Subscribe - Register interest to Topic. Specify Queue to distribute messages2. Publish - Asynchronously publish to Topic3. Encoding - Broker encodes Message to JSON
Registry Service Discovery
Service discovery using a message bus? What magic is this?
type Registry interface { Register(*Service, ...RegisterOption) error Deregister(*Service) error GetService(string) ([]*Service, error) ListServices() ([]*Service, error) Watch() (Watcher, error) String() string}
Broadcast Queries!
1. All services subscribe for queries on a broadcast topic2. Publish query on broadcast topic with reply address3. Instances of queried service respond4. Wait for responses until upper time limit5. Aggregate and return results
Scaling Like A Boss
Cluster per AZ or Region
Multi-AZ deployment
Fault tolerant of AZ failure
Pattern for high availability
Multi-region deployment
Use DNS latency based routing
Thanks for listening!
Micro on NATS blog post
blog.micro.mu/2016/04/11/micro-on-nats.html
Micro on GitHub Follow on Twitter!
github.com/micro @MicroHQ
Micro on Web Join the Slack community!
micro.mu slack.micro.mu