< Previous Challenge - Home - Next Challenge >
In this challenge, you’re going to add Dapr into the mix, using the Dapr service invocation building block.
While asynchronous communication across microservices is favored, some operations require an immediate response. For such use cases, one microservice effectively queries another for a response that is needed to complete the operation. Such scenarios often implement synchronous calls between services.
Operationally, it’s important to not hardcode endpoints when implementing synchronous service calls. This practice becomes especially important in orchestrated environments, such as Kubernetes, where services are continually moved across cluster nodes and replaced with newer versions. The Dapr service invocation building block addresses service-to-service communication. Here is how it works:
In Dapr, every service is started with a unique Id (the app-id) which can be used to find it. What happens if Service A needs to call Service B?
The service invocation building block offers many other features, such as security and load-balancing. Check out the Dapr documentation later to learn more.
Service Invocation is also covered in detail in the Dapr for .NET Developers guidance eBook.
For this hands-on challenge, you will decouple communication between two services.
VehicleRegistrationService
and the FineCollectionService
.FineCollectionService
(VehicleRegistrationService
class) so that it uses the Dapr service invocation building block to call the /vehicleinfo/{licensenumber}
endpoint on the VehicleRegistrationService
.This challenge targets the operations labeled as number 1 in the end-state setup:
VehicleRegistrationService
and FineCollectionService
each run with a Dapr sidecar. You’ll see both Dapr and application logging in the output.FineCollectionService
uses the Dapr service invocation building block to call the /vehicleinfo/{licensenumber}
endpoint on the VehicleRegistrationService
. The HTTP call should be to the Dapr port number, not the API port number.So how can you check whether or not the call to the VehicleRegistrationService
is handled by Dapr? Well, Dapr has some observability built in. You can look at Dapr traffic using Zipkin:
RUN QUERY
button in the top right of the screen to search for traces.FineCollectionService
and the VehicleRegistrationService
. You can expand and collapse each trace and click the SHOW
button to get more details:
Resources.zip
package provided by your coach for the source code to get started.dapr run
command to start up a Dapr sidecar & make sure and append the dotnet run
command at the end of the command to ensure that both services are started at the same time.app-id
of the VehicleRegistrationService
as the one used in the FineCollectionService
class.
app-id
of all Dapr services (some Dapr configurations don’t support CamelCase)!port in use
error). Use the following commands to help find the offending process and kill it:
lsof -i :<port>
ps -al | grep dapr
kill -9 <pid>