mirror of https://github.com/dapr/docs.git
Merge branch 'v1.11' into issue_3657
This commit is contained in:
commit
589fd4eacb
|
@ -108,7 +108,7 @@ All Dapr pub/sub components support the at-least-once guarantee.
|
||||||
|
|
||||||
### Consumer groups and competing consumers pattern
|
### Consumer groups and competing consumers pattern
|
||||||
|
|
||||||
Dapr handles the burden of dealing with consumer groups and the competing consumers pattern. In the competing consumers pattern, multiple application instances using a single consumer group compete for the message. Dapr enforces the competing conusmer pattern when replicas use the same `app-id` without explict consumer group overrides.
|
Dapr handles the burden of dealing with consumer groups and the competing consumers pattern. In the competing consumers pattern, multiple application instances using a single consumer group compete for the message. Dapr enforces the competing consumer pattern when replicas use the same `app-id` without explict consumer group overrides.
|
||||||
|
|
||||||
When multiple instances of the same application (with same `app-id`) subscribe to a topic, Dapr delivers each message to *only one instance of **that** application*. This concept is illustrated in the diagram below.
|
When multiple instances of the same application (with same `app-id`) subscribe to a topic, Dapr delivers each message to *only one instance of **that** application*. This concept is illustrated in the diagram below.
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ type: docs
|
||||||
title: "How-To: Invoke services using HTTP"
|
title: "How-To: Invoke services using HTTP"
|
||||||
linkTitle: "How-To: Invoke with HTTP"
|
linkTitle: "How-To: Invoke with HTTP"
|
||||||
description: "Call between services using service invocation"
|
description: "Call between services using service invocation"
|
||||||
weight: 2000
|
weight: 20
|
||||||
---
|
---
|
||||||
|
|
||||||
This article demonstrates how to deploy services each with an unique application ID for other services to discover and call endpoints on them using service invocation over HTTP.
|
This article demonstrates how to deploy services each with an unique application ID for other services to discover and call endpoints on them using service invocation over HTTP.
|
||||||
|
@ -19,26 +19,22 @@ This article demonstrates how to deploy services each with an unique application
|
||||||
|
|
||||||
Dapr allows you to assign a global, unique ID for your app. This ID encapsulates the state for your application, regardless of the number of instances it may have.
|
Dapr allows you to assign a global, unique ID for your app. This ID encapsulates the state for your application, regardless of the number of instances it may have.
|
||||||
|
|
||||||
{{< tabs Dotnet Java Python Go JavaScript Kubernetes>}}
|
{{< tabs Python JavaScript ".NET" Java Go Kubernetes >}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- python3 checkout/app.py
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 dotnet run
|
dapr run --app-id order-processor --app-port 8001 --app-protocol http --dapr-http-port 3501 -- python3 order-processor/app.py
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 dotnet run
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --app-protocol https --dapr-http-port 3500 -- python3 checkout/app.py
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 --app-protocol https dotnet run
|
dapr run --app-id order-processor --app-port 8001 --app-protocol https --dapr-http-port 3501 -- python3 order-processor/app.py
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 --app-protocol https dotnet run
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
@ -46,21 +42,17 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm start
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 mvn spring-boot:run
|
dapr run --app-id order-processor --app-port 5001 --app-protocol http --dapr-http-port 3501 -- npm start
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 mvn spring-boot:run
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --dapr-http-port 3500 --app-protocol https -- npm start
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 --app-protocol https mvn spring-boot:run
|
dapr run --app-id order-processor --app-port 5001 --dapr-http-port 3501 --app-protocol https -- npm start
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 --app-protocol https mvn spring-boot:run
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
@ -68,21 +60,17 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- dotnet run
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 -- python3 CheckoutService.py
|
dapr run --app-id order-processor --app-port 7001 --app-protocol http --dapr-http-port 3501 -- dotnet run
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 -- python3 OrderProcessingService.py
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --dapr-http-port 3500 --app-protocol https -- dotnet run
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 --app-protocol https -- python3 CheckoutService.py
|
dapr run --app-id order-processor --app-port 7001 --dapr-http-port 3501 --app-protocol https -- dotnet run
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 --app-protocol https -- python3 OrderProcessingService.py
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
@ -90,21 +78,17 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 go run CheckoutService.go
|
dapr run --app-id order-processor --app-port 9001 --app-protocol http --dapr-http-port 3501 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 go run OrderProcessingService.go
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --dapr-http-port 3500 --app-protocol https -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 --app-protocol https go run CheckoutService.go
|
dapr run --app-id order-processor --app-port 9001 --dapr-http-port 3501 --app-protocol https -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 --app-protocol https go run OrderProcessingService.go
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
@ -112,21 +96,17 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --dapr-http-port 3500 -- go run .
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 npm start
|
dapr run --app-id order-processor --app-port 6006 --app-protocol http --dapr-http-port 3501 -- go run .
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 npm start
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
If your app uses a TLS, you can tell Dapr to invoke your app over a TLS connection by setting `--app-protocol https`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
dapr run --app-id checkout --dapr-http-port 3500 --app-protocol https -- go run .
|
||||||
|
|
||||||
dapr run --app-id checkout --app-port 6002 --dapr-http-port 3602 --dapr-grpc-port 60002 --app-protocol https npm start
|
dapr run --app-id order-processor --app-port 6006 --dapr-http-port 3501 --app-protocol https -- go run .
|
||||||
|
|
||||||
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 --app-protocol https npm start
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
@ -156,7 +136,7 @@ spec:
|
||||||
app: <language>-app
|
app: <language>-app
|
||||||
annotations:
|
annotations:
|
||||||
dapr.io/enabled: "true"
|
dapr.io/enabled: "true"
|
||||||
dapr.io/app-id: "orderprocessingservice"
|
dapr.io/app-id: "order-processor"
|
||||||
dapr.io/app-port: "6001"
|
dapr.io/app-port: "6001"
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
@ -173,88 +153,7 @@ To invoke an application using Dapr, you can use the `invoke` API on any Dapr in
|
||||||
|
|
||||||
Below are code examples that leverage Dapr SDKs for service invocation.
|
Below are code examples that leverage Dapr SDKs for service invocation.
|
||||||
|
|
||||||
{{< tabs Dotnet Java Python Go Javascript>}}
|
{{< tabs Python JavaScript ".NET" Java Go >}}
|
||||||
|
|
||||||
{{% codetab %}}
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
//dependencies
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Dapr.Client;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
//code
|
|
||||||
namespace EventService
|
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static async Task Main(string[] args)
|
|
||||||
{
|
|
||||||
while(true) {
|
|
||||||
System.Threading.Thread.Sleep(5000);
|
|
||||||
Random random = new Random();
|
|
||||||
int orderId = random.Next(1,1000);
|
|
||||||
using var client = new DaprClientBuilder().Build();
|
|
||||||
|
|
||||||
//Using Dapr SDK to invoke a method
|
|
||||||
var result = client.CreateInvokeMethodRequest(HttpMethod.Get, "checkout", "checkout/" + orderId);
|
|
||||||
await client.InvokeMethodAsync(result);
|
|
||||||
Console.WriteLine("Order requested: " + orderId);
|
|
||||||
Console.WriteLine("Result: " + result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
{{% /codetab %}}
|
|
||||||
|
|
||||||
{{% codetab %}}
|
|
||||||
|
|
||||||
```java
|
|
||||||
//dependencies
|
|
||||||
import io.dapr.client.DaprClient;
|
|
||||||
import io.dapr.client.DaprClientBuilder;
|
|
||||||
import io.dapr.client.domain.HttpExtension;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
//code
|
|
||||||
@SpringBootApplication
|
|
||||||
public class OrderProcessingServiceApplication {
|
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(OrderProcessingServiceApplication.class);
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException{
|
|
||||||
while(true) {
|
|
||||||
TimeUnit.MILLISECONDS.sleep(5000);
|
|
||||||
Random random = new Random();
|
|
||||||
int orderId = random.nextInt(1000-1) + 1;
|
|
||||||
DaprClient daprClient = new DaprClientBuilder().build();
|
|
||||||
//Using Dapr SDK to invoke a method
|
|
||||||
var result = daprClient.invokeMethod(
|
|
||||||
"checkout",
|
|
||||||
"checkout/" + orderId,
|
|
||||||
null,
|
|
||||||
HttpExtension.GET,
|
|
||||||
String.class
|
|
||||||
);
|
|
||||||
log.info("Order requested: " + orderId);
|
|
||||||
log.info("Result: " + result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
{{% /codetab %}}
|
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
@ -263,20 +162,18 @@ public class OrderProcessingServiceApplication {
|
||||||
import random
|
import random
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import logging
|
import logging
|
||||||
from dapr.clients import DaprClient
|
import requests
|
||||||
|
|
||||||
#code
|
#code
|
||||||
logging.basicConfig(level = logging.INFO)
|
logging.basicConfig(level = logging.INFO)
|
||||||
while True:
|
while True:
|
||||||
sleep(random.randrange(50, 5000) / 1000)
|
sleep(random.randrange(50, 5000) / 1000)
|
||||||
orderId = random.randint(1, 1000)
|
orderId = random.randint(1, 1000)
|
||||||
with DaprClient() as daprClient:
|
#Invoke a service
|
||||||
#Using Dapr SDK to invoke a method
|
result = requests.post(
|
||||||
result = daprClient.invoke_method(
|
url='%s/orders' % (base_url),
|
||||||
"checkout",
|
data=json.dumps(order),
|
||||||
f"checkout/{orderId}",
|
headers=headers
|
||||||
data=b'',
|
|
||||||
http_verb="GET"
|
|
||||||
)
|
)
|
||||||
logging.basicConfig(level = logging.INFO)
|
logging.basicConfig(level = logging.INFO)
|
||||||
logging.info('Order requested: ' + str(orderId))
|
logging.info('Order requested: ' + str(orderId))
|
||||||
|
@ -287,50 +184,9 @@ while True:
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```go
|
|
||||||
//dependencies
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
"strconv"
|
|
||||||
dapr "github.com/dapr/go-sdk/client"
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
//code
|
|
||||||
type Order struct {
|
|
||||||
orderName string
|
|
||||||
orderNum string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
time.Sleep(5000)
|
|
||||||
orderId := rand.Intn(1000-1) + 1
|
|
||||||
client, err := dapr.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer client.Close()
|
|
||||||
ctx := context.Background()
|
|
||||||
//Using Dapr SDK to invoke a method
|
|
||||||
result, err := client.InvokeMethod(ctx, "checkout", "checkout/" + strconv.Itoa(orderId), "get")
|
|
||||||
log.Println("Order requested: " + strconv.Itoa(orderId))
|
|
||||||
log.Println("Result: ")
|
|
||||||
log.Println(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
{{% /codetab %}}
|
|
||||||
|
|
||||||
{{% codetab %}}
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
//dependencies
|
//dependencies
|
||||||
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from '@dapr/dapr';
|
import axios from "axios";
|
||||||
|
|
||||||
//code
|
//code
|
||||||
const daprHost = "127.0.0.1";
|
const daprHost = "127.0.0.1";
|
||||||
|
@ -346,18 +202,11 @@ var main = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function start(orderId) {
|
//Invoke a service
|
||||||
const client = new DaprClient({
|
const result = await axios.post('order-processor' , "orders/" + orderId , axiosConfig);
|
||||||
daprHost: daprHost,
|
|
||||||
daprPort: process.env.DAPR_HTTP_PORT,
|
|
||||||
communicationProtocol: CommunicationProtocolEnum.HTTP
|
|
||||||
});
|
|
||||||
|
|
||||||
//Using Dapr SDK to invoke a method
|
|
||||||
const result = await client.invoker.invoke('checkoutservice' , "checkout/" + orderId , HttpMethod.GET);
|
|
||||||
console.log("Order requested: " + orderId);
|
console.log("Order requested: " + orderId);
|
||||||
console.log("Result: " + result);
|
console.log("Result: " + result.config.data);
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
@ -368,6 +217,158 @@ main();
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
//dependencies
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
//code
|
||||||
|
namespace EventService
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
while(true) {
|
||||||
|
await Task.Delay(5000)
|
||||||
|
var random = new Random();
|
||||||
|
var orderId = random.Next(1,1000);
|
||||||
|
|
||||||
|
//Using Dapr SDK to invoke a method
|
||||||
|
var order = new Order("1");
|
||||||
|
var orderJson = JsonSerializer.Serialize<Order>(order);
|
||||||
|
var content = new StringContent(orderJson, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
var httpClient = DaprClient.CreateInvokeHttpClient();
|
||||||
|
await httpClient.PostAsJsonAsync($"http://order-processor/orders", content);
|
||||||
|
Console.WriteLine("Order requested: " + orderId);
|
||||||
|
Console.WriteLine("Result: " + result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
|
||||||
|
```java
|
||||||
|
//dependencies
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
//code
|
||||||
|
@SpringBootApplication
|
||||||
|
public class CheckoutServiceApplication {
|
||||||
|
private static final HttpClient httpClient = HttpClient.newBuilder()
|
||||||
|
.version(HttpClient.Version.HTTP_2)
|
||||||
|
.connectTimeout(Duration.ofSeconds(10))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException, IOException {
|
||||||
|
while (true) {
|
||||||
|
TimeUnit.MILLISECONDS.sleep(5000);
|
||||||
|
Random random = new Random();
|
||||||
|
int orderId = random.nextInt(1000 - 1) + 1;
|
||||||
|
|
||||||
|
// Create a Map to represent the request body
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
requestBody.put("orderId", orderId);
|
||||||
|
// Add other fields to the requestBody Map as needed
|
||||||
|
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(new JSONObject(requestBody).toString()))
|
||||||
|
.uri(URI.create(dapr_url))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("dapr-app-id", "order-processor")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
|
System.out.println("Order passed: " + orderId);
|
||||||
|
TimeUnit.MILLISECONDS.sleep(1000);
|
||||||
|
|
||||||
|
log.info("Order requested: " + orderId);
|
||||||
|
log.info("Result: " + response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
daprHttpPort := os.Getenv("DAPR_HTTP_PORT")
|
||||||
|
if daprHttpPort == "" {
|
||||||
|
daprHttpPort = "3500"
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 15 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
time.Sleep(5000)
|
||||||
|
orderId := rand.Intn(1000-1) + 1
|
||||||
|
|
||||||
|
url := fmt.Sprintf("http://localhost:%s/checkout/%v", daprHttpPort, orderId)
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding target app id as part of the header
|
||||||
|
req.Header.Add("dapr-app-id", "order-processor")
|
||||||
|
|
||||||
|
// Invoking a service
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
{{< /tabs >}}
|
{{< /tabs >}}
|
||||||
|
|
||||||
### Additional URL formats
|
### Additional URL formats
|
||||||
|
@ -432,4 +433,4 @@ For more information on tracing and logs, see the [observability]({{< ref observ
|
||||||
## Related Links
|
## Related Links
|
||||||
|
|
||||||
- [Service invocation overview]({{< ref service-invocation-overview.md >}})
|
- [Service invocation overview]({{< ref service-invocation-overview.md >}})
|
||||||
- [Service invocation API specification]({{< ref service_invocation_api.md >}})
|
- [Service invocation API specification]({{< ref service_invocation_api.md >}})
|
||||||
|
|
|
@ -3,7 +3,7 @@ type: docs
|
||||||
title: "How-To: Invoke Non-Dapr Endpoints using HTTP"
|
title: "How-To: Invoke Non-Dapr Endpoints using HTTP"
|
||||||
linkTitle: "How-To: Invoke Non-Dapr Endpoints"
|
linkTitle: "How-To: Invoke Non-Dapr Endpoints"
|
||||||
description: "Call Non-Dapr endpoints from Dapr applications using service invocation"
|
description: "Call Non-Dapr endpoints from Dapr applications using service invocation"
|
||||||
weight: 2000
|
weight: 40
|
||||||
---
|
---
|
||||||
|
|
||||||
This article demonstrates how to call a non-Dapr endpoint using Dapr over HTTP.
|
This article demonstrates how to call a non-Dapr endpoint using Dapr over HTTP.
|
||||||
|
|
|
@ -3,7 +3,7 @@ type: docs
|
||||||
title: "How-To: Invoke services using gRPC"
|
title: "How-To: Invoke services using gRPC"
|
||||||
linkTitle: "How-To: Invoke with gRPC"
|
linkTitle: "How-To: Invoke with gRPC"
|
||||||
description: "Call between services using service invocation"
|
description: "Call between services using service invocation"
|
||||||
weight: 3000
|
weight: 30
|
||||||
---
|
---
|
||||||
|
|
||||||
This article describe how to use Dapr to connect services using gRPC.
|
This article describe how to use Dapr to connect services using gRPC.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
type: docs
|
type: docs
|
||||||
title: "How to: Service invocation across namespaces"
|
title: "How to: Service invocation across namespaces"
|
||||||
linkTitle: "How to: Service invocation namespaces"
|
linkTitle: "How to: Service invocation namespaces"
|
||||||
weight: 1000
|
weight: 50
|
||||||
description: "Call between services deployed to different namespaces"
|
description: "Call between services deployed to different namespaces"
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
type: docs
|
type: docs
|
||||||
title: "Service invocation overview"
|
title: "Service invocation overview"
|
||||||
linkTitle: "Overview"
|
linkTitle: "Overview"
|
||||||
weight: 900
|
weight: 10
|
||||||
description: "Overview of the service invocation API building block"
|
description: "Overview of the service invocation API building block"
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -600,7 +600,7 @@ go build .
|
||||||
Run the `order-processor` service alongside a Dapr sidecar.
|
Run the `order-processor` service alongside a Dapr sidecar.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- go run .
|
dapr run --app-port 6006 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- go run .
|
||||||
```
|
```
|
||||||
|
|
||||||
Each order is received via an HTTP POST request and processed by the
|
Each order is received via an HTTP POST request and processed by the
|
||||||
|
|
|
@ -45,6 +45,7 @@ The table below shows the versions of Dapr releases that have been tested togeth
|
||||||
|
|
||||||
| Release date | Runtime | CLI | SDKs | Dashboard | Status | Release notes |
|
| Release date | Runtime | CLI | SDKs | Dashboard | Status | Release notes |
|
||||||
|--------------------|:--------:|:--------|---------|---------|---------|------------|
|
|--------------------|:--------:|:--------|---------|---------|---------|------------|
|
||||||
|
| August 31st 2023 | 1.11.3</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.3 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.3) |
|
||||||
| July 20th 2023 | 1.11.2</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.2 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.2) |
|
| July 20th 2023 | 1.11.2</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.2 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.2) |
|
||||||
| June 22nd 2023 | 1.11.1</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.1 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.1) |
|
| June 22nd 2023 | 1.11.1</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.1 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.1) |
|
||||||
| June 12th 2023 | 1.11.0</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.0 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.0) |
|
| June 12th 2023 | 1.11.0</br> | 1.11.0 | Java 1.9.0 </br>Go 1.8.0 </br>PHP 1.1.0 </br>Python 1.10.0 </br>.NET 1.11.0 </br>JS 3.1.0 | 0.13.0 | Supported (current) | [v1.11.0 release notes](https://github.com/dapr/dapr/releases/tag/v1.11.0) |
|
||||||
|
@ -121,7 +122,7 @@ General guidance on upgrading can be found for [self hosted mode]({{< ref self-h
|
||||||
| 1.8.0 to 1.8.6 | N/A | 1.9.6 |
|
| 1.8.0 to 1.8.6 | N/A | 1.9.6 |
|
||||||
| 1.9.0 | N/A | 1.9.6 |
|
| 1.9.0 | N/A | 1.9.6 |
|
||||||
| 1.10.0 | N/A | 1.10.8 |
|
| 1.10.0 | N/A | 1.10.8 |
|
||||||
| 1.11.0 | N/A | 1.11.2 |
|
| 1.11.0 | N/A | 1.11.3 |
|
||||||
|
|
||||||
|
|
||||||
## Upgrade on Hosting platforms
|
## Upgrade on Hosting platforms
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{- if .Get "short" }}1.11{{ else if .Get "long" }}1.11.2{{ else if .Get "cli" }}1.11.0{{ else }}1.11.2{{ end -}}
|
{{- if .Get "short" }}1.11{{ else if .Get "long" }}1.11.3{{ else if .Get "cli" }}1.11.0{{ else }}1.11.3{{ end -}}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 28 KiB |
Loading…
Reference in New Issue