Welcome to a new series of blog posts where we are going to explore dapr, for that we will see :
- Introduction to dapr
- Service Invocation
- Publish-Subscribe pub/sub
- State management
- Hosting using AKS (Azure Kubernetes Services)
Introduction to dapr .
Dapr is an open source, portable, event-driven runtime that makes it easy for developers to build resilient, microservice stateless and stateful applications that run on the cloud and edge. Dapr embraces the diversity of all programming languages and developer frameworks and simplifies building applications such as the e-commerce example.
Dapr consists of a set of building blocks accessed by standard HTTP or gRPC APIs that can be called from any programming language. These building blocks empower all developers with proven, industry best practices and each building block is independent; you can use one, some, or all of them in your applications. In addition, through the open source project, we welcome the community to add new building blocks and contribute new components into existing ones. Dapr is completely platform agnostic, meaning you can run your applications locally, on any Kubernetes cluster, and other hosting environments that Dapr integrates with. This enables developers to build microservice applications that can run on both the cloud and edge with no code changes.
With dapr you can build applications with any language and any framework by calling Dapr building blocks over standard APIs :
Portability does also extend beyond the hosting environment – while Dapr is an initiative started by Microsoft, it can also run on Kubernetes on-premise or in the cloud: Microsoft Azure, Amazon AWS, Google GCP, or any other cloud vendor…
Dapr provides several building blocks that microservice application developers can adopt selectively, based on their needs:
- Service invocation: Using service invocation, your application can reliably and securely communicate with other applications using the standard gRPC or HTTP protocols.
- State management: Using state management, your application can store data as key/value pairs in the supported state stores (we will see in a further blog post) .
- Publish & subscribe messaging: The publish/subscribe pattern allows microservices to communicate with each other using messages. The producer or publisher sends messages to a topic without knowledge of what application will receive them. This involves writing them to an input channel. Similarly, a consumer or subscriber subscribes to the topic and receives its messages without any knowledge of what service produced these messages.
- Bindings: Using bindings, you can trigger your app with events coming in from external systems, or interface with external systems.
- Actors: The actor pattern describes actors as the lowest-level “unit of computation”. In other words, you write your code in a self-contained unit (called an actor) that receives messages and processes them one at a time, without any kind of concurrency or threading.
- Observability: Dapr enables the developer and operator to observe the behavior of the system services and applications without having to instrument them.
- Secrets management: It’s common for applications to store sensitive information such as connection strings, keys and tokens that are used to authenticate with databases, services and external systems in secrets by using a dedicated secret store.
installing dapr :
Well, before we go any further with dapr , we need first to install it and for so we need a couple fo things to do :
- Dapr requires Docker locally on your development environment, therefore make
sure you have it installed : https://docs.docker.com/install
- Installing Dapr CLI :The Dapr CLI allows you to setup Dapr on your local dev machine or on a Kubernetes cluster, provides debugging support, launches and manages Dapr instances.
To install the Dapr CLI :
powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"
In order to verify that dapr have been installed we need to check the installation with this command:
Now that you have the Dapr CLI installed, it’s time to initialize Dapr on your local machine using the CLI.
Dapr runs as a sidecar alongside your application, and in self-hosted mode this means it is a process on your local machine. Therefore, initializing Dapr includes fetching the Dapr sidecar binaries and installing them locally.
make sure that docker is runing and open the terminal to run the follow cammand :
Now you can verify the installed version of dapr using :
Now one more thing we need to check is the containers are runing well :
For that and in order to follow this series , you need to make sure you have .Net installed (we will be working with .Net 5.0 ) and you may need to install visual studio or visual studio code.