Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Programming> Microservices> Practical Microservices with Dapr and .NET
Practical Microservices with Dapr and .NET
Practical Microservices with Dapr and .NET

Practical Microservices with Dapr and .NET: A developer's guide to building cloud-native applications using the event-driven runtime , Second Edition

Arrow left icon
Profile Icon Davide Bedin
Arrow right icon
$41.99
PaperbackNov 2022312 pages2nd Edition
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Davide Bedin
Arrow right icon
$41.99
PaperbackNov 2022312 pages2nd Edition
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature iconInstant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning
OR

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Shipping Address

Billing Address

Shipping Methods
Table of content iconView table of contentsPreview book icon Preview Book

Practical Microservices with Dapr and .NET

Introducing Dapr

Welcome to this second edition ofPractical Microservices with Dapr and .NET!Distributed Application Runtime (Dapr) evolved greatly after the version one release and the innovations in .NET 6 prompted a refreshed and enriched edition of the book.

This chapter will introduce you to the Dapr project to teach you the core concepts of its architecture and prepare you to develop with Dapr.

Dapr accelerates the development of new cloud-native applications and simplifies the adoption of a microservice architecture.

In this chapter, we are going to cover the following main topics:

  • Understanding Dapr
  • Exploring Dapr
  • Setting up Dapr
  • Building our first Dapr sample

Learning about these topics is important to establish a solid foundation for our future endeavors with Dapr and microservice architectures. These basic concepts will guide our learning throughout the rest of this book.

Our first steps into the project will start with exploring Dapr and understanding how it works.

Technical requirements

The code for this sample can be found on GitHub at https://github.com/PacktPublishing/Practical-Microservices-with-Dapr-and-.NET-Second-Edition/tree/main/chapter01.

In this chapter, the working area for scripts and code is expected to be<repository path>\chapter01\. In our local environment, it isC:\Repos\practical-dapr\chapter01.

Please refer to theSetting up Dapr section for a complete guide to the tools needed to develop with Dapr and work with the samples.

Understanding Dapr

Dapr is anevent-driven, portable runtime createdby Microsoft with an open source approach and it is aCloud Native Computing Foundation (CNCF) incubated project.

Being event-driven (which is emphasized in the definition of Dapr) plays an important role in microservices; this is because an application can be designed to efficiently react to events from external systems or other parts of the solution and to produce events as well in order to inform other services of new facts or to continue processing elsewhere, or at a later stage.

Dapr is portable as it can run locally on your development machine in self-hosted mode; it can also be deployed to the edge, or it can run on Kubernetes.

The following diagram shows the many building blocks provided by Dapr:

Figure 1.1 – Dapr architecture

Figure 1.1 – Dapr architecture

Portability doesalso extend beyond the hosting environment—while Dapris an initiative that was started by Microsoft, it canalso run on Kubernetes on-premises or in the cloud withMicrosoft Azure,Amazon Web Services(AWS),Google Cloud Platform (GCP), or any other cloud vendor.

Dapr has been built on the experience gained by Microsoft in developing hyperscale cloud-native applications. It has been inspired by the design of Orleans and Service Fabric, whichin turn enables many Microsoft Azure cloud services to operate resiliently and at a large scale.

A brief history of Dapr

Dapr was first released inOctober 2019, and you can find more information at https://cloudblogs.microsoft.com/opensource/2019/10/16/announcing-dapr-open-source-project-build-microservice-applications/.

Dapr adopted an open governance model early on in the initial development phase in September 2020; see the description at https://blog.dapr.io/posts/2020/09/30/transitioning-the-dapr-project-to-open-governance/.

Dapr reached the production-ready v1.0 release in February 2021; see https://blog.dapr.io/posts/2021/02/17/announcing-dapr-v1.0/ for more details. In November 2021, Dapr joined CNCF as an incubated project; see the announcement at https://blog.dapr.io/posts/2021/11/03/dapr-joins-cncf-as-an-incubating-project/.

Dapr offers developers an approach to design the tools to build and the runtime to operate applications, based on a microservice architecture style.

Microservices offer a vast array of benefits balanced by increased complexities in team and product management, usually with a significant burden on the developer and the team in order to get started.

What if you could leverage a runtime such as Dapr to help you get through the common patterns you will likely need to adopt, and thus ease your operations?

The following figure shows the two Dapr hosting modes:

Figure 1.2 – Dapr sidecar

Figure 1.2 – Dapr sidecar

As depicted inFigure 1.2, theDapr runtime operates in sidecar processes, lifting most of the complexity from the application to a separate environment, greatly simplifying developmentand operations as well. These sidecar processes are run locally in your development environment or as containers in a Pod on Kubernetes.

From anapplication perspective, Dapr is anApplication Programming Interface (API) that can be directly reached viaHyperText Transfer Protocol (HTTP),Remote Procedure Call (gRPC)calls, or, evenmore simply, via any of theSoftware Development Kits (SDKs) availablefor .NET, Java,Go, Python, PHP, JavaScript, C++, and Rust languages.

As we will experience later, it is not necessary to adopt the Dapr SDK in your application; a request to a Dapr service can be as simple as an HTTP call to an endpoint, such ashttp://localhost:3500/v1.0/invoke/<app-id>/method/<methodname>. Nevertheless, using the SDK does provide many benefits if you are writing a Dapr service adopting the server extensions, interacting with Dapr via the client SDK, or leveraging the Dapr actor model with the Actor SDK.

You can learnmore about SDKs and the supported languages in the Dapr docs athttps://docs.dapr.io/developing-applications/sdks/.

Now thatwe have learned about the high-level architecture of Dapr, it is time to also clarify what Dapr is not.

What Dapr is not

While we hope the overview of Dapr has informed and intrigued you enough to spend time on this book, when we have the chance to talk about Dapr, we often find ourselves in needof clarifying what Dapr isnot. This makes it easier to eliminate any misconceptions we may have about what Dapr does, as follows:

  • Dapr doesnot force the developer to embrace a programming model with strict rules and constraints. On the contrary, while the application developer is freed, by Dapr, of the many complexities of a microservice architecture, the developer is not mandated on how to write the application. As an example, the management of the connection to the database where the state is stored is a responsibility of Dapr and, as we will see in the following chapters, it is transparent to the microservice application code.
  • Dapr isnot a service mesh. While many similarities can be found in the general objectives of Dapr and service meshes, Dapr does provide these benefits at the application level, while a service mesh operates on the infrastructure. For instance, it is the developer’s responsibility to decide how to handle errors Dapr might return if there is a conflict or an intermittent issue; whether it is adopting a retry policy as provided by the Dapr resiliency configurations, raising an error back to the client, or compensating the operation, these are explicit choices only the developer can make.

Dapr is designed to be integrated with service meshes such as Istio, which is out of the scope of this book.

  • Dapr isnot a Microsoft cloud service. It does help the developer build microservice applications in the cloud, and it surely provides many integrations with Azurecloud services, but it also has as many components forAWS, GCP, and other services. At thesame time, Azure does offer rich support to Dapr inAzure Kubernetes Service (AKS) with the native extension, inAzure API Management with Dapr policies, and inAzure Container Apps with Dapr native integration.
  • Dapr isnot a .NET only technology. Dapr itself has been written in the Go language and anylanguage can leverage it. SDKs for many languages are available but you can also choose to interact directly with the Dapr API without any additional library.

Important note

While this book is heavily skewed toward .NET, Dapr does provide the same benefits to Python developers (just as an example) as it provides SDKs for Dapr and Dapr Actor, with Kubernetes as the deployment target—Dapr welcomes all developers in a vendor-neutral and open approach.

We hope this perspective on the Dapr objectives and role will help you in properly adopting this technology. The next section will be dedicated to understanding the architecture of Dapr.

Exploring Dapr

Dapr has beendesigned from the ground up as a set of pluggable building blocks—developers can create an application counting on the support of many facilities, while operators can adapt applications to the hosting environment by simply intervening in the configuration.

The followingis a complete list of the tools and components of Dapr:

  • The Dapr command-line interface (CLI): A cross-platform command-line tool toconfigure, manage, and monitor the Dapr environment. It is also the tool used to locally debug Dapr applications.
  • Dapr Helm charts: It is worthmentioning that Helm charts are provided for a richer experience in installing and updating Dapr in a Kubernetes environment.
  • The Dapr API: The API thatdefines how an application can interact with the Dapr runtime in order to leverage its building blocks.
  • The Dapr runtime: This is thecore of Dapr that implements the API. If you are curious, you can take a look at how it is developed in Go at Dapr’s repository at https://github.com/dapr/dapr.
  • The Dapr host: On yourdevelopment machine, the host runs as a standalone process; in Kubernetes, it is a sidecar container in your application’s pod.
  • The Dapr operator: Specificto Kubernetes mode, the operator manages bindings and configurations.
  • The Dapr sidecar injector: Once instructed via configuration in Kubernetes mode, thistakes care ofinjecting the Dapr sidecar into your application pod.
  • The Dapr placement service: Thisservice has the objective of distributing (or placing) Actor instances across the Dapr pods.
  • Dapr Sentry: Abuilt-inCertificate Authority (CA) to issueand manage certificates usedby Dapr to provide transparentmutual Transport Layer Security (mTLS).

Dapr provides several building blocks that microservice application developers can adopt selectively, based on their needs, and they are as follows:

  • Service invocation: Service-to-service invocation enables your code to call otherservices located in the same hosting environment while taking care of the retry policy.

This building block is presented in more detail inChapter 4,Service-to-Service Invocation.

  • State management: This is to efficiently manage the application state as a simpleKey-Value Pair (KVP), relieving your stateful or stateless services of the need tosupport different backends. Dapr provides many state stores, which include Redis, Azure Cosmos DB, Azure SQL Server, and PostgreSQL, which can be plugged in via configuration.

You can learn about this building block inChapter 5,Introducing State Management.

  • Publish and subscribe (pub/sub) messaging: The pub/sub pattern enables decoupled communication between microservices by exchanging messages, counting on the presence of a service bus, which can route messages betweenproducers and consumers.

A discussion of this building block is presented inChapter 6,Publish and Subscribe.

  • Resource bindings: This is where the event-driven nature of Dapr shines. With bindings, yourapplication can be triggered by aShort Message Service (SMS) message sent via Twilio (just one of the popular services in the area of communication API).

This building block is presented in more detail inChapter 7,ResourceBindings.

  • Actors: The actor pattern aims to simplify highly concurrent scenarios by splitting the overall request load between a large number of computation units (the actors), which take care of the job in their smaller, but independent, scope by processing requests to a single actor one at a time. Dapr provides great benefits in this space.

You can learn about this building block inChapter 8,Using Actors.

  • Observability: Dapr enables the developer and operator toobserve the behavior of the system services and applications without having to instrument them.

This building block is presented in more detail inChapter 11,Tracing Dapr Applications.

  • Secrets: It is a healthy practice to keep secrets segregated from the code. Dapr enables you to store secrets and to reference these from other components, in Kubernetes or Azure Key Vault, among many options.
  • Configuration: Introduced in Dapr version 1.8 in Alpha state, this building block addresses the common need to retrieve the configuration data needed by an application.
  • Distributed lock: Introduced with Dapr version 1.8 in Alpha state, it provides a powerfullease-based mechanism to manage mutually exclusive access to a named lock. The lock can be used by the application to assure exclusive access to a resource by many concurrent instances.

After learning about Dapr architecture and components, and before we can start using them, we need to set up Dapr in our development environment, which will be the topic of the next section.

Setting up Dapr

Dapr is a runtime for every platform and every language. The focus of this book is on C# in .NET, used withVisual Studio Code (VS Code). The code snippets in the book can be appreciatedby developers from anybackground, but nevertheless, you will get the most out of it from a .NET perspective.

The development environment we use is Windows, as you will be able to tell from the screenshots we use in the book. While the CLI, configuration, and files will be the same, if you need more details on how to perform a particularaction on Linux or a macOS developmentmachine, we encourage you to check the Dapr documentation at https://docs.dapr.io/.

Dapr roadmap

The Dapr runtime reached the v1.0 production-ready release in February 2021, as announced in the Dapr blog at https://blog.dapr.io/posts/2021/02/17/announcing-dapr-v1.0/, and five new minor versions have been released during 2021. You can learnmore about the Dapr roadmap athttps://docs.dapr.io/contributing/roadmap/.

The samples and scripts in this book have been updated and tested with v1.8 of Dapr.

In this book, we will also leverage several services on the Azure cloud platform (https://azure.microsoft.com/en-us/explore/), whether as a platform to execute Dapr applications, for exchanging messages via Azure, or for storing data.

Access to an Azure subscription is required. Each chapter will give you instructions and directyou to documentation for further information.

Next, we will accomplish the following steps:

  • Configuring Docker
  • Installing the Dapr CLI
  • Installing .NET
  • Installing VS Code
  • Installing Windows Terminal
  • Installing Dapr in self-hosted mode
  • Installing Dapr on Kubernetes

Let’s start with Docker.

Docker

Dapr requires Docker tobe present locally in your development environment; therefore, make sure you have it installed. If your development machine is Windows, Docker must be running in Linux container mode.

You canfind detailed instructions for running Docker at https://docs.docker.com/install/.

Intalling the Dapr CLI

We will immediatelystart working with Dapr; therefore, you need to installall the necessary tools. The Dapr runtime and its tools can be found athttps://github.com/dapr/cli.

On Windows, execute the following command to install the CLI in thec:/dapr directory and add it to the userPATH environment variable so that the tools can be easily found from the command line:

powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"

For more details on the Dapr CLI, please refer to https://docs.dapr.io/getting-started/install-dapr-cli/.

We still need to initialize Dapr on the development machine, which we will do in theInstalling Dapr in self-hosted mode section of this chapter.

Installing .NET

To install .NET 6, pleaserefer to https://dotnet.microsoft.com/download forthe link to the latest binaries.

.NET 6 isaLong-Term Support (LTS) version of .NET, which getsfree support and patches for3 years. Refer to https://dotnet.microsoft.com/en-us/platform/support/policy for more details on the .NET support policy.

On a development machine, it makes sense to install the full SDK, which includes the runtime. Once the install is complete, open a new command prompt and run thedotnet --info command. You should see the following output:

PS C:\Repos\dapr-samples\chapter01> dotnet --info.NET SDK (reflecting any global.json): Version:   6.0.101 Commit:    ef49f6213aRuntime Environment: OS Name:     Windows OS Version:  10.0.22000 OS Platform: Windows RID:         win10-x64 Base Path:   C:\Program Files\dotnet\sdk\6.0.101\Host (useful for support):  Version: 6.0.1  Commit:  3a25a7f1cc …

This proves that .NET hasbeen recognized and the framework is workingfine.

Installing VS Code

VS Code is agreat multiplatformsource code editor by Microsoft. You caninstall it for free by following the instructions at https://code.visualstudio.com/docs/setup/windows.

The Dapr extension

Dapr has an extension for VS Code that helps with navigating the Dapr local environmentand eases the debuggingconfiguration—we highlyrecommend it. Please follow the instructions at https://docs.dapr.io/developing-applications/ides/vscode/.

Installing Windows Terminal

We really lovethe new Windows Terminal (https://aka.ms/terminal) for its ease of use and configurability. In thefollowing chapters, we will often have to runmultiple commands and tools in parallel. Therefore, the tabs feature of Windows Terminal is just one of the reasons why we suggest you adopt it too.

Installing Dapr in self-hosted mode

Dapr can beinitialized intwo modes:self-hosted (or standalone) andKubernetes.

As it is intended to be used for a development environment, the self-hosted mode locally installs Redis, the Dapr placement services, and Zipkin. The following command initializes Dapr in your local environment:

dapr init

The Dapr binaries and default components to leverage Redis are by default positioned in the%USERPROFILE%\.dapr\ folder.

In a local development environment, it might happen that the ports Dapr might intend to use for Redis, for example, are already in use. In this case, you should identify which processes or containers are using the ports and change them accordingly.

Once you launch theinit command, the following is the output you should expect:

PS C:\Repos\practical-dapr\chapter01> dapr initMaking the jump to hyperspace...Installing runtime version 1.8.4Downloading binaries and setting up components...Downloaded binaries and completed components set up.daprd binary has been installed to C:\Users\dabedin\.dapr\bin.dapr_placement container is running.dapr_redis container is running.dapr_zipkin container is running.Use `docker ps` to check running containers.Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started

To check your newly initialized Dapr environment, you can usedocker ps as follows:

PS C:\Repos\practical-dapr\chapter01> docker ps --format "{{.Image}} - {{.Ports}} - {{.Names}}"daprio/dapr:1.8.4 - 0.0.0.0:6050->50005/tcp, :::6050->50005/tcp- dapr_placementopenzipkin/zipkin - 9410/tcp, 0.0.0.0:9411->9411/tcp, :::9411->9411/tcp - dapr_zipkinredis - 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp - dapr_redis

The outputshows the Dockercontainer for Dapr running on our machine.

Installing Dapr on Kubernetes

Dapr is specificallyintended to be executed on Kubernetes. From your development machine on which youhave the Dapr CLI installed, you can set up Dapr on the Kubernetes cluster currently configured as follows:

dapr init -k

Alternatively, you can install Dapr on Kubernetes with a Helm v3 chart. You can find more details at https://docs.dapr.io/getting-started/install-dapr-kubernetes/#install-with-helm-advanced.

Important note

If you intend to define aContinuous Integration/Continuous Deployment (CI/CD) pipeline that takes care of the Dapr installation on the Kubernetes cluster too, this canalso work, although it is out of scope for the present setup.

To verify theinstallation was successfully completed, execute thefollowing command:

kubectl get pods --namespace dapr-system

The command should display the pods in thedapr-system namespace.

Updating Dapr version

On a developmentWindows machine on which a previous version of Dapr was already present, the CLI can be updated by simply re-installing with the command we saw in a previous section.

As described in https://docs.dapr.io/operations/hosting/self-hosted/self-hosted-upgrade/, on a Windows development machine on which a previous version of Dapr was already present, you must uninstall Dapr first as follows:

PS C:\Repos\practical-dapr\chapter01> dapr uninstall --all

With the CLI updated and Dapr uninstalled, we can repeat the Dapr installation as follows:

PS C:\Repos\practical-dapr\chapter01> dapr init

After we executedapr init, checking the Dapr version, we can see it has now moved forward from 1.0 to 1.1 for both the CLI and the runtime, as illustrated in the following code snippet:

PS C:\Repos\practical-dapr\chapter01> dapr --versionCLI version:  1.8.1 Runtime version: 1.8.4

Our Dapr testenvironment is up and running. We are now ready to try itwith our first sample.

Building our first Dapr sample

It is time tosee Dapr in action. We are going to build a web API that returns ahello world message. We chose to base all our samples in theC:\Repos\practical-dapr\ folder, and we created aC:\Repos\practical-dapr\chapter01 folder for this first sample. We’ll take the following steps:

  1. Let’s start by creating a Web API ASP.NET project as follows:
    PS C:\Repos\practical-dapr\chapter01> dotnet new webapi
    -o dapr.microservice.webapi
  2. Then, we add the reference to the Dapr SDK for ASP.NET. The current version is1.5.0. You can look for the package versions on NuGet athttps://www.nuget.org/packages/Dapr.Actors.AspNetCore with thedotnet add package command, as illustrated in the following code snippet:
    PS C:\Repos\practical-dapr\chapter01> dotnet add package
    Dapr.AspNetCore --version 1.8.0
  3. We need to apply some changes to the template we used to create the project. These are going to be much easier to do via VS Code—with the<directory>\code . command, we open it in the scope of the project folder.
  4. To support Dapr in ASP.NET 6 and leverage minimal hosting and global usings, we made a few changes to the code inProgram.cs. We changed thebuilder.Services.AddControllers() method tobuilder.Services.AddControllers().AddDapr().

We also addedapp.MapSubscribeHandler(). While this is not necessary for our sample, as we will not use the pub/sub features of Dapr, it is better to have it in mind as the base set of changes you need to apply to a default ASP.NET project.

Finally, in order to simplify the code, we commentedapp.UseHttpsRedirection().

Thefollowing is the modified code of theProgram.cs class:

var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddControllers().AddDapr();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();var app = builder.Build();// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment()){    app.UseSwagger();    app.UseSwaggerUI();}//app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();app.MapSubscribeHandler();app.Run();

In thepreceding code block, we instructed Dapr to leverage theModel-View-Controller (MVC) pattern in ASP.NET 6.

  1. Finally, we added a controller namedHelloWorldController as illustrated in thefollowing code snippet:
    using Microsoft.AspNetCore.Mvc;
    namespace dapr.microservice.webapi.Controllers;
    [ApiController]
    [Route("[controller]")]
    public class HelloController : ControllerBase
    {
        private readonly ILogger<HelloController> _logger;
        public HelloController(ILogger<HelloController>
          logger)
        {
            _logger = logger;
        }
        [HttpGet()]
        public ActionResult<string> Get()
        {
            Console.WriteLine("Hello, World.");
            return "Hello, World";
        }
    }

In the preceding code snippet, you can see[Route] and[HttpGet]. These ASP.NET attributes are evaluated by the routing to identify the method name.

  1. In order to run a Dapr application, you use the following command structure:
    dapr run --app-id <your app id> --app-port <port of the
    application> --dapr-http-port <port in Dapr> dotnet run

We left the ASP.NET default port as5000 but we changed the Dapr HTTP port to5010. The following command line launches the Dapr application:

PS C:\Repos\practical-dapr\chapter01\dapr.microservice.webapi> dapr run --app-id hello-world --app-port 5000--dapr-http-port 5010 dotnet runStarting Dapr with id hello-world. HTTP Port: 5010. gRPCPort: 52443

Theinitial message informs you that Dapr is going to use port5010 for HTTP as specified, while for gRPC, it is going to auto-select an available port.

The log from Dapr is full of information. To confirm your application is running correctly in the context of the Dapr runtime, you can look for the following code:

Updating metadata for app command: dotnet runYou're up and running! Both Dapr and your app logs willappear here.

At this stage, ASP.NET is responding locally on port5000 and Dapr is responding on port5010. In order to test Dapr, let’s invoke acurl command as follows, and using the browser is equally fine:

PS C:\Repos\practical-dapr\chapter01> curl http://localhost:5010/v1.0/invoke/hello-world/method/helloHello, World

This exciting response has been returned by Dapr, which passed our (the client’s) initial request to the ASP.NET Web API framework. You should also see that the same result logged asConsole.WriteLine sends its output to the Dapr window as follows:

== APP == Hello, World.
  1. From another window, let’s verify our Dapr service details. Instead of using thedapr list command, let’s open the Dapr dashboard as follows:
    PS C:\Windows\System32> dapr dashboard
    Dapr Dashboard running on http://localhost:8080

Wecan open the dashboard by navigating tohttp://localhost:8080 to reveal the following screen:

Figure 1.3 – Dapr dashboard application

Figure 1.3 – Dapr dashboard application

The Dapr dashboard shown inFigure 1.3 illustrates the details of ourhello-world application.

In this case, the Dapr dashboard shows only this sample application we are running onthe development machine. In a Kubernetes environment, it would show all the microservices running, along with the other components.

The Dapr dashboard also displays the configured components in the hosting environment, as we can see in the following screenshot:

Figure 1.4 – Dapr dashboard components

Figure 1.4 – Dapr dashboard components

InFigure 1.4, the Dapr dashboard shows us that the local installation of Redis is configuredas state store and pub/sub components, in addition to the deployment of Zipkin.

This ends our introductory section, where we were able to build our first Dapr sample.

Summary

In this chapter, you have learned about the Dapr project, its components, building blocks, and the sidecar approach. All of these concepts will be explored individually in further depth in the following chapters. You are now able to set up Dapr on your local development machine and prepare all the necessary tools to make this experience easier.

You have also learned how to create a simple ASP.NET project and how to configure and check Dapr, and we have had a glimpse of the Dapr dashboard where we can gain a complete and immediate view of the Dapr environment.

In the next chapter, we will use the newly created environment to learn how to debug Dapr.

Questions

  1. Which building blocks does Dapr provide?
  2. What is the relationship between the Dapr CLI and Dapr runtime?
  3. How can you install Dapr on your local development environment?
  4. Which alternative methods can you follow to install Dapr in Kubernetes?

Further reading

  • Overview of Dapr: https://docs.dapr.io/concepts/overview/
  • Getting Started with Dapr: https://docs.dapr.io/getting-started/
  • Roadmap of Dapr: https://docs.dapr.io/contributing/roadmap/
Left arrow icon

Page1 of 9

Right arrow icon
Download code iconDownload Code

Key benefits

  • Build resilient, stateless, and stateful microservice applications that run on the cloud and edge
  • Overcome common issues in distributed systems, such as low latency and scaling, using any language and framework
  • Learn how to expose and operate Dapr applications with multiple options

Description

This second edition will help you get to grips with microservice architectures and how to manage application complexities with Dapr in no time. You'll understand how Dapr simplifies development while allowing you to work with multiple languages and platforms. Following a C# sample, you'll understand how Dapr's runtime, building blocks, and software development kits (SDKs) help you to simplify the creation of resilient and portable microservices.Dapr provides an event-driven runtime that supports the essential features you need for building microservices, including service invocation, state management, and publish/subscribe messaging. You'll explore all of those in addition to various other advanced features with this practical guide to learning Dapr. With a focus on deploying the Dapr sample application to an Azure Kubernetes Service cluster and to the Azure Container Apps serverless platform, you’ll see how to expose the Dapr application with NGINX, YARP, and Azure API Management.By the end of this book, you'll be able to write microservices easily by implementing industry best practices to solve problems related to distributed systems.

Who is this book for?

This book is for developers looking to explore and implement microservices architectures in Dapr applications using .NET examples. Whether you are new to microservices or have knowledge of this architectural approach and want to get hands-on experience using Dapr, you’ll find this book useful. Familiarity with .NET will help you to understand the C# samples and code snippets used in the book.

What you will learn

  • Use Dapr to create services, invoking them directly and via pub/sub
  • Discover best practices for working with microservice architectures
  • Leverage the actor model to orchestrate data and behavior
  • Expose API built with Dapr applications via NGINX and Azure API Management
  • Use Azure Kubernetes Service to deploy a sample application
  • Monitor Dapr applications using Zipkin, Prometheus, and Grafana
  • Scale and load test Dapr applications on Kubernetes
  • Get to grips with Azure Container Apps as you combine Dapr with a serverless platform
Estimated delivery feeDeliver to United States

Economy delivery10 - 13 business days

Free $6.95

Premium delivery6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Nov 11, 2022
Length:312 pages
Edition :2nd
Language :English
ISBN-13 :9781803248127
Vendor :
Microsoft
Category :
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature iconInstant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning
OR

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Shipping Address

Billing Address

Shipping Methods
Estimated delivery feeDeliver to United States

Economy delivery10 - 13 business days

Free $6.95

Premium delivery6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date :Nov 11, 2022
Length:312 pages
Edition :2nd
Language :English
ISBN-13 :9781803248127
Vendor :
Microsoft
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
$199.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts
$279.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts

Frequently bought together


C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals
C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals
Read more
Nov 2022818 pages
Full star icon4.1 (54)
eBook
eBook
$35.98$39.99
$49.99
Apps and Services with .NET 7
Apps and Services with .NET 7
Read more
Nov 2022814 pages
Full star icon4.8 (27)
eBook
eBook
$35.98$39.99
$49.99
Practical Microservices with Dapr and .NET
Practical Microservices with Dapr and .NET
Read more
Nov 2022312 pages
eBook
eBook
$29.99$33.99
$41.99
Stars icon
Total$141.97
C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals
$49.99
Apps and Services with .NET 7
$49.99
Practical Microservices with Dapr and .NET
$41.99
Total$141.97Stars icon

Table of Contents

19 Chapters
Part 1: Introduction to DaprChevron down iconChevron up icon
Part 1: Introduction to Dapr
Chapter 1: Introducing DaprChevron down iconChevron up icon
Chapter 1: Introducing Dapr
Technical requirements
Understanding Dapr
Exploring Dapr
Setting up Dapr
Building our first Dapr sample
Summary
Questions
Further reading
Chapter 2: Debugging Dapr SolutionsChevron down iconChevron up icon
Chapter 2: Debugging Dapr Solutions
Technical requirements
Configuring VS Code debug for Dapr
Debugging a Dapr multi-project solution
Using Tye with Dapr
Summary
Questions
Further reading
Chapter 3: Microservices Architecture with DaprChevron down iconChevron up icon
Chapter 3: Microservices Architecture with Dapr
Introducing our sample solution
Discovering microservices
Adopting microservices patterns
Building an e-commerce architecture
Building microservices with Dapr
Summary
Questions
Further reading
Part 2: Building Microservices with DaprChevron down iconChevron up icon
Part 2: Building Microservices with Dapr
Chapter 4: Service-to-Service InvocationChevron down iconChevron up icon
Chapter 4: Service-to-Service Invocation
Technical requirements
Invoking services with Dapr
Service invocation with the .NET SDK
Comparing HTTP and gRPC for Dapr
Summary
Questions
Further reading
Chapter 5: Introducing State ManagementChevron down iconChevron up icon
Chapter 5: Introducing State Management
Technical requirements
Managing state in Dapr
Stateful services in an e-commerce ordering system
Using Azure Cosmos DB as a state store
Summary
Chapter 6: Publish and SubscribeChevron down iconChevron up icon
Chapter 6: Publish and Subscribe
Technical requirements
Using the pub/sub pattern in Dapr
Using Azure Service Bus (ASB) in Dapr
Implementing a saga pattern
Summary
Chapter 7: Resource BindingsChevron down iconChevron up icon
Chapter 7: Resource Bindings
Technical requirements
Learning how to use Dapr bindings
Using Twilio output bindings in Dapr
Ingesting data with the Azure Event Hubs input binding
Summary
Chapter 8: Using ActorsChevron down iconChevron up icon
Chapter 8: Using Actors
Technical requirements
Using actors in Dapr
Actor concurrency, consistency, and lifetime
Implementing actors in an e-commerce reservation system
Summary
Part 3: Deploying and Scaling Dapr SolutionsChevron down iconChevron up icon
Part 3: Deploying and Scaling Dapr Solutions
Chapter 9: Deploying to KubernetesChevron down iconChevron up icon
Chapter 9: Deploying to Kubernetes
Technical requirements
Setting up Kubernetes
Setting up Dapr on Kubernetes
Deploying a Dapr application to Kubernetes
Exposing Dapr applications to external clients
Summary
Chapter 10: Exposing Dapr ApplicationsChevron down iconChevron up icon
Chapter 10: Exposing Dapr Applications
Technical requirements
Daprizing ingress controllers
Setting up API management on Kubernetes
Configuring Dapr policies with API management
Summary
Chapter 11: Tracing Dapr ApplicationsChevron down iconChevron up icon
Chapter 11: Tracing Dapr Applications
Technical requirements
Observing applications in Dapr
Tracing with Zipkin
Analyzing metrics with Prometheus and Grafana
Summary
Chapter 12: Load Testing and Scaling DaprChevron down iconChevron up icon
Chapter 12: Load Testing and Scaling Dapr
Technical requirements
Scaling Dapr on Kubernetes
Load testing with Locust
Load testing Dapr
Autoscaling with KEDA
Summary
Chapter 13: Leveraging Serverless Containers with DaprChevron down iconChevron up icon
Chapter 13: Leveraging Serverless Containers with Dapr
Technical requirements
Learning about the Azure Container Apps architecture
Setting up Azure Container Apps
Deploying Dapr with Azure Container Apps
Autoscaling Azure Container Apps with KEDA
Summary
AssessmentsChevron down iconChevron up icon
Assessments
Chapter 1, Introducing Dapr
Chapter 2, Debugging Dapr Solutions
Chapter 3, Microservices Architecture with Dapr
Chapter 4, Service-to-Service Invocation
IndexChevron down iconChevron up icon
Index
Why subscribe?
Other Books You May EnjoyChevron down iconChevron up icon
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Download a free PDF copy of this book

Recommendations for you

Left arrow icon
Debunking C++ Myths
Debunking C++ Myths
Read more
Dec 2024226 pages
Full star icon5 (1)
eBook
eBook
$27.99$31.99
$39.99
Go Recipes for Developers
Go Recipes for Developers
Read more
Dec 2024350 pages
eBook
eBook
$27.99$31.99
$39.99
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (68)
eBook
eBook
$35.98$39.99
$49.99
$49.99
Asynchronous Programming with C++
Asynchronous Programming with C++
Read more
Nov 2024424 pages
Full star icon5 (1)
eBook
eBook
$29.99$33.99
$41.99
Modern CMake for C++
Modern CMake for C++
Read more
May 2024504 pages
Full star icon4.7 (12)
eBook
eBook
$35.98$39.99
$49.99
Learn Python Programming
Learn Python Programming
Read more
Nov 2024616 pages
Full star icon5 (1)
eBook
eBook
$31.99$35.99
$39.99
Learn to Code with Rust
Learn to Code with Rust
Read more
Nov 202457hrs 40mins
Video
Video
$74.99
Modern Python Cookbook
Modern Python Cookbook
Read more
Jul 2024818 pages
Full star icon4.9 (21)
eBook
eBook
$38.99$43.99
$54.99
Right arrow icon

People who bought this also bought

Left arrow icon
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (68)
eBook
eBook
$35.98$39.99
$49.99
$49.99
Event-Driven Architecture in Golang
Event-Driven Architecture in Golang
Read more
Nov 2022384 pages
Full star icon4.9 (11)
eBook
eBook
$35.98$39.99
$49.99
The Python Workshop Second Edition
The Python Workshop Second Edition
Read more
Nov 2022600 pages
Full star icon4.6 (22)
eBook
eBook
$36.99$41.99
$51.99
Template Metaprogramming with C++
Template Metaprogramming with C++
Read more
Aug 2022480 pages
Full star icon4.6 (14)
eBook
eBook
$33.99$37.99
$46.99
Domain-Driven Design with Golang
Domain-Driven Design with Golang
Read more
Dec 2022204 pages
Full star icon4.4 (19)
eBook
eBook
$31.99$35.99
$44.99
Right arrow icon

About the author

Profile icon Davide Bedin
Davide Bedin
Davide Bedin is a cloud-native architecture enthusiast, with strong and relevant experience with cloud platforms. As CTO of an ISV, Davide led its significant transformational process with the objective of creating new solutions based on the Microsoft Azure cloud. Davide particularly focused on the evolution of distributed computing to service-oriented architectures, and ultimately microservices, spending most of his developer career creating web services. As a Cloud Solution Architect at Microsoft, Davide is responsible for the guidance and support of enterprise customers in embracing the cloud paradigm, a key enabler of their digital transformation; lately, he also plays with Dapr.
Read more
See other products by Davide Bedin
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order?Chevron down iconChevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book?Chevron down iconChevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium:Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge?Chevron down iconChevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order?Chevron down iconChevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries:www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges?Chevron down iconChevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live inMexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live inTurkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order?Chevron down iconChevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy?Chevron down iconChevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged?Chevron down iconChevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use?Chevron down iconChevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books?Chevron down iconChevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium:Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela

[8]ページ先頭

©2009-2025 Movatter.jp