Code Monkey home page Code Monkey logo

dapr.sample's Introduction

An example microservice using Dapr

Dapr Overview

Dapr enables developers using any language or framework to easily write microservices. It addresses many of the challenges found that come along with distributed applications, such as:

  • How can distributed services discover each other and communicate synchronously?
  • How an they implement asynchronous messaging?
  • How can they maintain contextual information across a transaction?
  • How can they become resilient to failure?
  • How can they scale to meet fluctuating demand?
  • How are they monitored and observed?

If you are new to Dapr, you may want to review following resources first:

Prerequisites

Docker

Services

This example defintion has the following containerized services:

  • orderservice
  • orderservice-darp // Order service Dapr Sidecar
  • productservice
  • productservice-dapr // Product service Dapr Sidecar
  • notificationservice
  • notificationservice-dapr // Notification service Dapr Sidecar
  • placement // Dapr's placement service
  • redis
  • zipkin
  • seq

Tracing

Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. Features include both the collection and lookup of this data.

image

Logging

Seq is the intelligent search, analysis, and alerting server built specifically for modern structured log data.

image

Testing

  • Install RestClient into visual studio code.
  • Use product.test.http to test product service.
  • Use order.test.http to test order service.

Dapr with Docker-compose

Overview

This sample demonstrates how to get Dapr running locally with Docker Compose.

Prerequisites

Docker-compose

Networking

Each of these services is deployed to the darp-sample Docker network and have their own IP on that network. Each of these services is sharing a network namespace with their associated app service by using network_mode. This means that the app and the sidecars are able to communicate over their localhost interface.

Ports are still bound on the host machine, therefore, we need to ensure we avoid port conflicts.

Volumes

In order to get Dapr to load the redis statestore and pubsub components, you need to mount the ./components directory to the default working directory. These component definitions have been modified to talk to redis using a DNS name redis rather than localhost. This resolves on the Docker network to the IP of the container running redis.

Deploy the Docker Compose Definition

To deploy the above docker-compose.yml you can run:

docker-compose up

Clean up

docker-compose down

Additional Resources:

Overview of Docker Compose

Dapr with Tye

Under development

Dapr with Kubernetes

Prerequisites

Please follow this article to enable Kubernetes on Docker Desktop.

Deploy on Kubernetes

  • Make sure you enabled Kubernetes mode on your Docker Desktop.
  • Run deploy-dapr.ps1 to install dapr to your cluster.
  • Run deploy-infrastructure.ps1 to install dapr components and config component.
  • Run deploy-app.ps1 to install order service, product service and notification service.
  • You need to expose order service and product service to external IP address in order to test with Post man or Rest Client.
kubectl port-forward service/orderservice 5001:80
kubectl port-forward service/productservice 5002:80

Note:

  • You need to expose zipkin and seq as well if you want to view tracing and logging.
kubectl port-forward service/zipkin 9411:9411
kubectl port-forward service/seq 6500:80

Undeploy

  • Run undeploy-app.ps1 and undeploy-infrastructure.ps1 to uninstall all component and services.

Ingress Controller

If you want to use ingress controller as a gateway. Run deploy-ingress.ps1 then you can access order service and product service.

Note: Make sure there is no process uses port 80.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.