Service Invocation
Service Invocation is a Dapr building block that enables you to call methods on microservices using HTTP or gRPC protocols. Dapr handles service discovery, routing, and secure communication between services.
Key Features
- Supports HTTP and gRPC protocols
- Built-in service discovery using Dapr sidecars
- Secure communication with mutual TLS
- Automatic retries and error handling
Example Usage
- C#
- Java
- Python
// Call a method on another service using Dapr client
var client = new DaprClientBuilder().Build();
var result = await client.InvokeMethodAsync<string>("order-service", "createOrder", orderData);
// Call a method on another service using Dapr client
DaprClient client = new DaprClientBuilder().build();
String result = client.invokeMethod("order-service", "createOrder", orderData, String.class).block();
# Call a method on another service using Dapr client
from dapr.clients import DaprClient
with DaprClient() as client:
resp = client.invoke_method('order-service', 'createOrder', data=order_data)
Real-World Application
You use Service Invocation to connect microservices in a distributed system. For example, an API gateway can call backend services for order processing, inventory, or billing. Dapr ensures requests are routed securely and reliably.
Related Links
Was this page useful?