快速入门:发布和订阅

开始使用 Dapr 的发布和订阅构建块

让我们来看看Dapr的发布和订阅(Pub/sub)构建块。 在本快速入门中,您将运行发布者微服务和订阅者微服务,以演示 Dapr 如何启用发布/订阅模式。

  1. 使用发布者服务,开发人员可以重复向topic发布消息。
  2. 一个Pub/sub组件将这些消息排队或传递给代理。 我们下面的例子使用Redis,你可以使用RabbitMQ、Kafka等。
  3. 该topic的订阅者从队列中提取消息并对其进行处理。

发布与订阅 - 图1

您可以通过以下两种方式尝试此发布/订阅快速入门:

使用多应用程序运行

在继续快速入门之前,请选择您首选的特定语言 Dapr SDK。

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

从 Quickstarts 目录的根目录导航到 pub/sub 目录:

  1. cd pub_sub/python/sdk

安装 order-processorcheckout 应用的依赖项:

  1. cd ./checkout
  2. pip3 install -r requirements.txt
  3. cd ..
  4. cd ./order-processor
  5. pip3 install -r requirements.txt
  6. cd ..
  7. cd ./order-processor-fastapi
  8. pip3 install -r requirements.txt
  9. cd ..

步骤 3:运行发布者和订阅者

通过以下命令,同时运行以下服务,并在其自己的 Dapr sidecar 旁边运行:

  • order-processor 订阅者
  • checkout发布者
  1. dapr run -f .

注意:由于Python3.exe在Windows中未定义,您可能需要在运行dapr run -f .之前,将python3更改为python,请参考dapr.yaml文件。

预期输出

  1. == APP - checkout-sdk == Published data: Order { OrderId = 1 }
  2. == APP - order-processor == Subscriber received : Order { OrderId = 1 }
  3. == APP - checkout-sdk == Published data: Order { OrderId = 2 }
  4. == APP - order-processor == Subscriber received : Order { OrderId = 2 }
  5. == APP - checkout-sdk == Published data: Order { OrderId = 3 }
  6. == APP - order-processor == Subscriber received : Order { OrderId = 3 }
  7. == APP - checkout-sdk == Published data: Order { OrderId = 4 }
  8. == APP - order-processor == Subscriber received : Order { OrderId = 4 }
  9. == APP - checkout-sdk == Published data: Order { OrderId = 5 }
  10. == APP - order-processor == Subscriber received : Order { OrderId = 5 }
  11. == APP - checkout-sdk == Published data: Order { OrderId = 6 }
  12. == APP - order-processor == Subscriber received : Order { OrderId = 6 }
  13. == APP - checkout-sdk == Published data: Order { OrderId = 7 }
  14. == APP - order-processor == Subscriber received : Order { OrderId = 7 }
  15. == APP - checkout-sdk == Published data: Order { OrderId = 8 }
  16. == APP - order-processor == Subscriber received : Order { OrderId = 8 }
  17. == APP - checkout-sdk == Published data: Order { OrderId = 9 }
  18. == APP - order-processor == Subscriber received : Order { OrderId = 9 }
  19. == APP - checkout-sdk == Published data: Order { OrderId = 10 }
  20. == APP - order-processor == Subscriber received : Order { OrderId = 10 }
  21. Exited App successfully

发生了什么?

当您在安装 Dapr 期间运行 dapr init 时,以下 YAML 文件将在 .dapr/components 目录中生成:

在此快速入门中运行 dapr run -f .,启动了订阅者发布者 应用程序。

dapr.yaml 多应用运行模板文件

使用 dapr run -f . 运行多应用运行模板文件,启动项目中的所有应用程序。 在这个快速入门中,dapr.yaml文件包含以下内容:

  1. version: 1
  2. common:
  3. resourcesPath: ../../components/
  4. apps:
  5. - appID: order-processor-sdk
  6. appDirPath: ./order-processor/
  7. appPort: 6001
  8. command: ["uvicorn", "app:app"]
  9. - appID: checkout-sdk
  10. appDirPath: ./checkout/
  11. command: ["python3", "app.py"]
pubsub.yaml 组件文件

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。
order-processor 订阅者

order-processor订阅者中,您订阅名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. # Register Dapr pub/sub subscriptions
  2. @app.route('/dapr/subscribe', methods=['GET'])
  3. def subscribe():
  4. subscriptions = [{
  5. 'pubsubname': 'orderpubsub',
  6. 'topic': 'orders',
  7. 'route': 'orders'
  8. }]
  9. print('Dapr pub/sub is subscribed to: ' + json.dumps(subscriptions))
  10. return jsonify(subscriptions)
  11. # Dapr subscription in /dapr/subscribe sets up this route
  12. @app.route('/orders', methods=['POST'])
  13. def orders_subscriber():
  14. event = from_http(request.headers, request.get_data())
  15. print('Subscriber received : ' + event.data['orderid'], flush=True)
  16. return json.dumps({'success': True}), 200, {
  17. 'ContentType': 'application/json'}
  18. app.run(port=5001)
checkout发布者

checkout 发布者中,你将 orderId 消息发布到名为 orderpubsub(在 pubsub.yaml 组件中定义)和 topic 为 orders 的 Redis 实例。 一旦服务启动,它就会循环发布:

  1. with DaprClient() as client:
  2. # Publish an event/message using Dapr PubSub
  3. result = client.publish_event(
  4. pubsub_name='orderpubsub',
  5. topic_name='orders',
  6. data=json.dumps(order),
  7. data_content_type='application/json',
  8. )

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

从 Quickstarts 目录的根目录导航到 pub/sub 目录:

  1. cd pub_sub/javascript/sdk

安装 order-processorcheckout 应用的依赖项:

  1. cd ./order-processor
  2. npm install
  3. cd ..
  4. cd ./checkout
  5. npm install
  6. cd ..

步骤 3:运行发布者和订阅者

通过以下命令,同时运行以下服务,并在其自己的 Dapr sidecar 旁边运行:

  • order-processor 订阅者
  • checkout发布者
  1. dapr run -f .

预期输出

  1. == APP - checkout-sdk == Published data: Order { OrderId = 1 }
  2. == APP - order-processor == Subscriber received : Order { OrderId = 1 }
  3. == APP - checkout-sdk == Published data: Order { OrderId = 2 }
  4. == APP - order-processor == Subscriber received : Order { OrderId = 2 }
  5. == APP - checkout-sdk == Published data: Order { OrderId = 3 }
  6. == APP - order-processor == Subscriber received : Order { OrderId = 3 }
  7. == APP - checkout-sdk == Published data: Order { OrderId = 4 }
  8. == APP - order-processor == Subscriber received : Order { OrderId = 4 }
  9. == APP - checkout-sdk == Published data: Order { OrderId = 5 }
  10. == APP - order-processor == Subscriber received : Order { OrderId = 5 }
  11. == APP - checkout-sdk == Published data: Order { OrderId = 6 }
  12. == APP - order-processor == Subscriber received : Order { OrderId = 6 }
  13. == APP - checkout-sdk == Published data: Order { OrderId = 7 }
  14. == APP - order-processor == Subscriber received : Order { OrderId = 7 }
  15. == APP - checkout-sdk == Published data: Order { OrderId = 8 }
  16. == APP - order-processor == Subscriber received : Order { OrderId = 8 }
  17. == APP - checkout-sdk == Published data: Order { OrderId = 9 }
  18. == APP - order-processor == Subscriber received : Order { OrderId = 9 }
  19. == APP - checkout-sdk == Published data: Order { OrderId = 10 }
  20. == APP - order-processor == Subscriber received : Order { OrderId = 10 }
  21. Exited App successfully

发生了什么?

当您在安装 Dapr 期间运行 dapr init 时,以下 YAML 文件将在 .dapr/components 目录中生成:

在此快速入门中运行 dapr run -f .,启动了订阅者发布者 应用程序。

dapr.yaml 多应用运行模板文件

使用 dapr run -f . 运行多应用运行模板文件,启动项目中的所有应用程序。 在这个快速入门中,dapr.yaml文件包含以下内容:

  1. version: 1
  2. common:
  3. resourcesPath: ../../components/
  4. apps:
  5. - appID: order-processor
  6. appDirPath: ./order-processor/
  7. appPort: 5002
  8. command: ["npm", "run", "start"]
  9. - appID: checkout-sdk
  10. appDirPath: ./checkout/
  11. command: ["npm", "run", "start"]
pubsub.yaml 组件文件

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。
order-processor 订阅者

order-processor订阅者中,您订阅名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. server.pubsub.subscribe("orderpubsub", "orders", (data) => console.log("Subscriber received: " + JSON.stringify(data)));
checkout发布者

checkout发布者服务中,您将orderId消息发布到名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 一旦服务启动,它就会循环发布:

  1. const client = new DaprClient();
  2. await client.pubsub.publish(PUBSUB_NAME, PUBSUB_TOPIC, order);
  3. console.log("Published data: " + JSON.stringify(order));

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

从 Quickstarts 目录的根目录导航到 pub/sub 目录:

  1. cd pub_sub/csharp/sdk

安装 order-processorcheckout 应用的依赖项:

  1. cd ./order-processor
  2. dotnet restore
  3. dotnet build
  4. cd ../checkout
  5. dotnet restore
  6. dotnet build
  7. cd ..

步骤 3:运行发布者和订阅者

通过以下命令,同时运行以下服务,并在其自己的 Dapr sidecar 旁边运行:

  • order-processor 订阅者
  • checkout发布者
  1. dapr run -f .

预期输出

  1. == APP - checkout-sdk == Published data: Order { OrderId = 1 }
  2. == APP - order-processor == Subscriber received : Order { OrderId = 1 }
  3. == APP - checkout-sdk == Published data: Order { OrderId = 2 }
  4. == APP - order-processor == Subscriber received : Order { OrderId = 2 }
  5. == APP - checkout-sdk == Published data: Order { OrderId = 3 }
  6. == APP - order-processor == Subscriber received : Order { OrderId = 3 }
  7. == APP - checkout-sdk == Published data: Order { OrderId = 4 }
  8. == APP - order-processor == Subscriber received : Order { OrderId = 4 }
  9. == APP - checkout-sdk == Published data: Order { OrderId = 5 }
  10. == APP - order-processor == Subscriber received : Order { OrderId = 5 }
  11. == APP - checkout-sdk == Published data: Order { OrderId = 6 }
  12. == APP - order-processor == Subscriber received : Order { OrderId = 6 }
  13. == APP - checkout-sdk == Published data: Order { OrderId = 7 }
  14. == APP - order-processor == Subscriber received : Order { OrderId = 7 }
  15. == APP - checkout-sdk == Published data: Order { OrderId = 8 }
  16. == APP - order-processor == Subscriber received : Order { OrderId = 8 }
  17. == APP - checkout-sdk == Published data: Order { OrderId = 9 }
  18. == APP - order-processor == Subscriber received : Order { OrderId = 9 }
  19. == APP - checkout-sdk == Published data: Order { OrderId = 10 }
  20. == APP - order-processor == Subscriber received : Order { OrderId = 10 }
  21. Exited App successfully

发生了什么?

当您在安装 Dapr 期间运行 dapr init 时,以下 YAML 文件将在 .dapr/components 目录中生成:

在此快速入门中运行 dapr run -f .,启动了订阅者发布者 应用程序。

dapr.yaml 多应用运行模板文件

使用 dapr run -f . 运行多应用运行模板文件,启动项目中的所有应用程序。 在这个快速入门中,dapr.yaml文件包含以下内容:

  1. version: 1
  2. common:
  3. resourcesPath: ../../components/
  4. apps:
  5. - appID: order-processor
  6. appDirPath: ./order-processor/
  7. appPort: 7006
  8. command: ["dotnet", "run"]
  9. - appID: checkout-sdk
  10. appDirPath: ./checkout/
  11. command: ["dotnet", "run"]
pubsub.yaml 组件文件

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。
order-processor 订阅者

order-processor订阅者中,您订阅名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. // Dapr subscription in [Topic] routes orders topic to this route
  2. app.MapPost("/orders", [Topic("orderpubsub", "orders")] (Order order) => {
  3. Console.WriteLine("Subscriber received : " + order);
  4. return Results.Ok(order);
  5. });
  6. public record Order([property: JsonPropertyName("orderId")] int OrderId);
checkout发布者

checkout 发布者中,你将 orderId 消息发布到名为 orderpubsub(在 pubsub.yaml 组件中定义)和 topic 为 orders 的 Redis 实例。 一旦服务启动,它就会循环发布:

  1. using var client = new DaprClientBuilder().Build();
  2. await client.PublishEventAsync("orderpubsub", "orders", order);
  3. Console.WriteLine("Published data: " + order);

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

从 Quickstarts 目录的根目录导航到 pub/sub 目录:

  1. cd pub_sub/java/sdk

安装 order-processorcheckout 应用的依赖项:

  1. cd ./order-processor
  2. mvn clean install
  3. cd ..
  4. cd ./checkout
  5. mvn clean install
  6. cd ..

步骤 3:运行发布者和订阅者

通过以下命令,同时运行以下服务,并在其自己的 Dapr sidecar 旁边运行:

  • order-processor 订阅者
  • checkout发布者
  1. dapr run -f .

预期输出

  1. == APP - checkout-sdk == Published data: Order { OrderId = 1 }
  2. == APP - order-processor == Subscriber received : Order { OrderId = 1 }
  3. == APP - checkout-sdk == Published data: Order { OrderId = 2 }
  4. == APP - order-processor == Subscriber received : Order { OrderId = 2 }
  5. == APP - checkout-sdk == Published data: Order { OrderId = 3 }
  6. == APP - order-processor == Subscriber received : Order { OrderId = 3 }
  7. == APP - checkout-sdk == Published data: Order { OrderId = 4 }
  8. == APP - order-processor == Subscriber received : Order { OrderId = 4 }
  9. == APP - checkout-sdk == Published data: Order { OrderId = 5 }
  10. == APP - order-processor == Subscriber received : Order { OrderId = 5 }
  11. == APP - checkout-sdk == Published data: Order { OrderId = 6 }
  12. == APP - order-processor == Subscriber received : Order { OrderId = 6 }
  13. == APP - checkout-sdk == Published data: Order { OrderId = 7 }
  14. == APP - order-processor == Subscriber received : Order { OrderId = 7 }
  15. == APP - checkout-sdk == Published data: Order { OrderId = 8 }
  16. == APP - order-processor == Subscriber received : Order { OrderId = 8 }
  17. == APP - checkout-sdk == Published data: Order { OrderId = 9 }
  18. == APP - order-processor == Subscriber received : Order { OrderId = 9 }
  19. == APP - checkout-sdk == Published data: Order { OrderId = 10 }
  20. == APP - order-processor == Subscriber received : Order { OrderId = 10 }
  21. Exited App successfully

发生了什么?

当您在安装 Dapr 期间运行 dapr init 时,以下 YAML 文件将在 .dapr/components 目录中生成:

在此快速入门中运行 dapr run -f .,启动了订阅者发布者 应用程序。

dapr.yaml 多应用运行模板文件

使用 dapr run -f . 运行多应用运行模板文件,启动项目中的所有应用程序。 在这个快速入门中,dapr.yaml文件包含以下内容:

  1. version: 1
  2. common:
  3. resourcesPath: ../../components/
  4. apps:
  5. - appID: order-processor-sdk
  6. appDirPath: ./order-processor/target/
  7. appPort: 8080
  8. command: ["java", "-jar", "OrderProcessingService-0.0.1-SNAPSHOT.jar"]
  9. - appID: checkout-sdk
  10. appDirPath: ./checkout/target/
  11. command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"]
pubsub.yaml 组件文件

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。
order-processor 订阅者

order-processor订阅者中,您订阅名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. @Topic(name = "orders", pubsubName = "orderpubsub")
  2. @PostMapping(path = "/orders", consumes = MediaType.ALL_VALUE)
  3. public Mono<ResponseEntity> getCheckout(@RequestBody(required = false) CloudEvent<Order> cloudEvent) {
  4. return Mono.fromSupplier(() -> {
  5. try {
  6. logger.info("Subscriber received: " + cloudEvent.getData().getOrderId());
  7. return ResponseEntity.ok("SUCCESS");
  8. } catch (Exception e) {
  9. throw new RuntimeException(e);
  10. }
  11. });
  12. }
checkout发布者

checkout 发布者中,你将 orderId 消息发布到名为 orderpubsub(在 pubsub.yaml 组件中定义)和 topic 为 orders 的 Redis 实例。 一旦服务启动,它就会循环发布:

  1. DaprClient client = new DaprClientBuilder().build();
  2. client.publishEvent(
  3. PUBSUB_NAME,
  4. TOPIC_NAME,
  5. order).block();
  6. logger.info("Published data: " + order.getOrderId());

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

从 Quickstarts 目录的根目录导航到 pub/sub 目录:

  1. cd pub_sub/go/sdk

安装 order-processorcheckout 应用的依赖项:

  1. cd ./order-processor
  2. go build .
  3. cd ../checkout
  4. go build .
  5. cd ..

步骤 3:运行发布者和订阅者

通过以下命令,同时运行以下服务,并在其自己的 Dapr sidecar 旁边运行:

  • order-processor 订阅者
  • checkout发布者
  1. dapr run -f .

预期输出

  1. == APP - checkout-sdk == Published data: Order { OrderId = 1 }
  2. == APP - order-processor == Subscriber received : Order { OrderId = 1 }
  3. == APP - checkout-sdk == Published data: Order { OrderId = 2 }
  4. == APP - order-processor == Subscriber received : Order { OrderId = 2 }
  5. == APP - checkout-sdk == Published data: Order { OrderId = 3 }
  6. == APP - order-processor == Subscriber received : Order { OrderId = 3 }
  7. == APP - checkout-sdk == Published data: Order { OrderId = 4 }
  8. == APP - order-processor == Subscriber received : Order { OrderId = 4 }
  9. == APP - checkout-sdk == Published data: Order { OrderId = 5 }
  10. == APP - order-processor == Subscriber received : Order { OrderId = 5 }
  11. == APP - checkout-sdk == Published data: Order { OrderId = 6 }
  12. == APP - order-processor == Subscriber received : Order { OrderId = 6 }
  13. == APP - checkout-sdk == Published data: Order { OrderId = 7 }
  14. == APP - order-processor == Subscriber received : Order { OrderId = 7 }
  15. == APP - checkout-sdk == Published data: Order { OrderId = 8 }
  16. == APP - order-processor == Subscriber received : Order { OrderId = 8 }
  17. == APP - checkout-sdk == Published data: Order { OrderId = 9 }
  18. == APP - order-processor == Subscriber received : Order { OrderId = 9 }
  19. == APP - checkout-sdk == Published data: Order { OrderId = 10 }
  20. == APP - order-processor == Subscriber received : Order { OrderId = 10 }
  21. Exited App successfully

发生了什么?

当您在安装 Dapr 期间运行 dapr init 时,以下 YAML 文件将在 .dapr/components 目录中生成:

在此快速入门中运行 dapr run -f .,启动了订阅者发布者 应用程序。

dapr.yaml 多应用运行模板文件

使用 dapr run -f . 运行多应用运行模板文件,启动项目中的所有应用程序。 在这个快速入门中,dapr.yaml文件包含以下内容:

  1. version: 1
  2. common:
  3. resourcesPath: ../../components/
  4. apps:
  5. - appID: order-processor
  6. appDirPath: ./order-processor/
  7. appPort: 6005
  8. command: ["go", "run", "."]
  9. - appID: checkout-sdk
  10. appDirPath: ./checkout/
  11. command: ["go", "run", "."]
pubsub.yaml 组件文件

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。
order-processor 订阅者

order-processor订阅者中,您订阅名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
  2. fmt.Println("Subscriber received: ", e.Data)
  3. return false, nil
  4. }
checkout发布者

checkout 发布者中,你将 orderId 消息发布到名为 orderpubsub(在 pubsub.yaml 组件中定义)和 topic 为 orders 的 Redis 实例。 一旦服务启动,它就会循环发布:

  1. client, err := dapr.NewClient()
  2. if err := client.PublishEvent(ctx, PUBSUB_NAME, PUBSUB_TOPIC, []byte(order)); err != nil {
  3. panic(err)
  4. }
  5. fmt.Println("Published data: ", order)

一次只运行一个应用程序

在继续快速入门之前,请选择您首选的特定语言 Dapr SDK。

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

第3步:订阅topic

在终端窗口中,从 Quickstarts 克隆目录的根目录 导航到 order-processor 目录。

  1. cd pub_sub/python/sdk/order-processor

安装依赖项:

  1. pip3 install -r requirements.txt

在Dapr sidecar旁边运行order-processor订阅者服务。

  1. dapr run --app-id order-processor --resources-path ../../../components/ --app-port 6002 -- python3 app.py

注意:由于Python3.exe在Windows中未定义,您可能需要使用python app.py而不是python3 app.py

order-processor 订阅者中,我们订阅名为 orderpubsub(在 pubsub.yaml 组件中定义)和topic为 orders 的 Redis 实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. # Register Dapr pub/sub subscriptions
  2. @app.route('/dapr/subscribe', methods=['GET'])
  3. def subscribe():
  4. subscriptions = [{
  5. 'pubsubname': 'orderpubsub',
  6. 'topic': 'orders',
  7. 'route': 'orders'
  8. }]
  9. print('Dapr pub/sub is subscribed to: ' + json.dumps(subscriptions))
  10. return jsonify(subscriptions)
  11. # Dapr subscription in /dapr/subscribe sets up this route
  12. @app.route('/orders', methods=['POST'])
  13. def orders_subscriber():
  14. event = from_http(request.headers, request.get_data())
  15. print('Subscriber received : ' + event.data['orderid'], flush=True)
  16. return json.dumps({'success': True}), 200, {
  17. 'ContentType': 'application/json'}
  18. app.run(port=5001)

第4步:发布topic

在一个新的终端窗口中,导航到 checkout 目录。

  1. cd pub_sub/python/sdk/checkout

安装依赖项:

  1. pip3 install -r requirements.txt

与 Dapr sidecar 一起运行 checkout 发布者服务。

  1. dapr run --app-id checkout --resources-path ../../../components/ -- python3 app.py

注意:由于Python3.exe在Windows中未定义,您可能需要使用python app.py而不是python3 app.py

checkout发布者中,我们将orderId消息发布到名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 一旦服务启动,它就会循环发布:

  1. with DaprClient() as client:
  2. # Publish an event/message using Dapr PubSub
  3. result = client.publish_event(
  4. pubsub_name='orderpubsub',
  5. topic_name='orders',
  6. data=json.dumps(order),
  7. data_content_type='application/json',
  8. )

第5步:查看Pub/sub输出

发布者将订单发送给 Dapr sidecar,而订阅者接收这些订单。

发布者输出:

  1. == APP == INFO:root:Published data: {"orderId": 1}
  2. == APP == INFO:root:Published data: {"orderId": 2}
  3. == APP == INFO:root:Published data: {"orderId": 3}
  4. == APP == INFO:root:Published data: {"orderId": 4}
  5. == APP == INFO:root:Published data: {"orderId": 5}
  6. == APP == INFO:root:Published data: {"orderId": 6}
  7. == APP == INFO:root:Published data: {"orderId": 7}
  8. == APP == INFO:root:Published data: {"orderId": 8}
  9. == APP == INFO:root:Published data: {"orderId": 9}
  10. == APP == INFO:root:Published data: {"orderId": 10}

订阅者输出:

  1. == APP == INFO:root:Subscriber received: {"orderId": 1}
  2. == APP == INFO:root:Subscriber received: {"orderId": 2}
  3. == APP == INFO:root:Subscriber received: {"orderId": 3}
  4. == APP == INFO:root:Subscriber received: {"orderId": 4}
  5. == APP == INFO:root:Subscriber received: {"orderId": 5}
  6. == APP == INFO:root:Subscriber received: {"orderId": 6}
  7. == APP == INFO:root:Subscriber received: {"orderId": 7}
  8. == APP == INFO:root:Subscriber received: {"orderId": 8}
  9. == APP == INFO:root:Subscriber received: {"orderId": 9}
  10. == APP == INFO:root:Subscriber received: {"orderId": 10}
pubsub.yaml 组件文件

当你运行dapr init时,Dapr会创建一个默认的Redispubsub.yaml并在你的本地机器上运行一个Redis容器,它位于:

  • 在Windows上,在 %UserProfile%\.dapr\components\pubsub.yaml
  • 在Linux/MacOS上,在~/.dapr/components/pubsub.yaml

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

第3步:订阅topic

在终端窗口中,从 Quickstarts 克隆目录的根目录 导航到 order-processor 目录。

  1. cd pub_sub/javascript/sdk/order-processor

安装依赖项,其中将包括 JavaScript SDK 中的 @dapr/dapr 包:

  1. npm install

验证服务目录中是否包含以下文件:

  • package.json
  • package-lock.json

在Dapr sidecar旁边运行order-processor订阅者服务。

  1. dapr run --app-port 5002 --app-id order-processing --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- npm run start

order-processor 订阅者中,我们订阅名为 orderpubsub(在 pubsub.yaml 组件中定义)和topic为 orders 的 Redis 实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. server.pubsub.subscribe("orderpubsub", "orders", (data) => console.log("Subscriber received: " + JSON.stringify(data)));

第4步:发布topic

在新的终端窗口中,从 Quickstarts 克隆目录的根目录导航到 checkout 目录。

  1. cd pub_sub/javascript/sdk/checkout

安装依赖项,其中将包括 JavaScript SDK 中的 @dapr/dapr 包:

  1. npm install

验证服务目录中是否包含以下文件:

  • package.json
  • package-lock.json

与 Dapr sidecar 一起运行 checkout 发布者服务。

  1. dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- npm run start

checkout发布者服务中,我们将orderId消息发布到名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 一旦服务启动,它就会循环发布:

  1. const client = new DaprClient();
  2. await client.pubsub.publish(PUBSUB_NAME, PUBSUB_TOPIC, order);
  3. console.log("Published data: " + JSON.stringify(order));

第5步:查看Pub/sub输出

请注意,正如上面代码中所指定的,发布者向Dapr sidecar推送一个随机数 ,而订阅者接收它。

发布者输出:

  1. == APP == Published data: {"orderId":1}
  2. == APP == Published data: {"orderId":2}
  3. == APP == Published data: {"orderId":3}
  4. == APP == Published data: {"orderId":4}
  5. == APP == Published data: {"orderId":5}
  6. == APP == Published data: {"orderId":6}
  7. == APP == Published data: {"orderId":7}
  8. == APP == Published data: {"orderId":8}
  9. == APP == Published data: {"orderId":9}
  10. == APP == Published data: {"orderId":10}

订阅者输出:

  1. == APP == Subscriber received: {"orderId":1}
  2. == APP == Subscriber received: {"orderId":2}
  3. == APP == Subscriber received: {"orderId":3}
  4. == APP == Subscriber received: {"orderId":4}
  5. == APP == Subscriber received: {"orderId":5}
  6. == APP == Subscriber received: {"orderId":6}
  7. == APP == Subscriber received: {"orderId":7}
  8. == APP == Subscriber received: {"orderId":8}
  9. == APP == Subscriber received: {"orderId":9}
  10. == APP == Subscriber received: {"orderId":10}
pubsub.yaml 组件文件

当你运行dapr init时,Dapr会创建一个默认的Redispubsub.yaml并在你的本地机器上运行一个Redis容器,它位于:

  • 在Windows上,在 %UserProfile%\.dapr\components\pubsub.yaml
  • 在Linux/MacOS上,在~/.dapr/components/pubsub.yaml

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

第3步:订阅topic

在终端窗口中,从 Quickstarts 克隆目录的根目录 导航到 order-processor 目录。

  1. cd pub_sub/csharp/sdk/order-processor

还原 NuGet 包:

  1. dotnet restore
  2. dotnet build

在Dapr sidecar旁边运行order-processor订阅者服务。

  1. dapr run --app-id order-processor --resources-path ../../../components --app-port 7006 -- dotnet run

order-processor 订阅者中,我们订阅名为 orderpubsub(在 pubsub.yaml 组件中定义)和topic为 orders 的 Redis 实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. // Dapr subscription in [Topic] routes orders topic to this route
  2. app.MapPost("/orders", [Topic("orderpubsub", "orders")] (Order order) => {
  3. Console.WriteLine("Subscriber received : " + order);
  4. return Results.Ok(order);
  5. });
  6. public record Order([property: JsonPropertyName("orderId")] int OrderId);

第4步:发布topic

在新的终端窗口中,从 Quickstarts 克隆目录的根目录导航到 checkout 目录。

  1. cd pub_sub/csharp/sdk/checkout

还原 NuGet 包:

  1. dotnet restore
  2. dotnet build

与 Dapr sidecar 一起运行 checkout 发布者服务。

  1. dapr run --app-id checkout --resources-path ../../../components -- dotnet run

checkout发布者中,我们将orderId消息发布到名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 一旦服务启动,它就会循环发布:

  1. using var client = new DaprClientBuilder().Build();
  2. await client.PublishEventAsync("orderpubsub", "orders", order);
  3. Console.WriteLine("Published data: " + order);

第5步:查看Pub/sub输出

请注意,正如上面代码中所指定的,发布者向Dapr sidecar推送一个随机数 ,而订阅者接收它。

发布者输出:

  1. == APP == Published data: Order { OrderId = 1 }
  2. == APP == Published data: Order { OrderId = 2 }
  3. == APP == Published data: Order { OrderId = 3 }
  4. == APP == Published data: Order { OrderId = 4 }
  5. == APP == Published data: Order { OrderId = 5 }
  6. == APP == Published data: Order { OrderId = 6 }
  7. == APP == Published data: Order { OrderId = 7 }
  8. == APP == Published data: Order { OrderId = 8 }
  9. == APP == Published data: Order { OrderId = 9 }
  10. == APP == Published data: Order { OrderId = 10 }

订阅者输出:

  1. == APP == Subscriber received: Order { OrderId = 1 }
  2. == APP == Subscriber received: Order { OrderId = 2 }
  3. == APP == Subscriber received: Order { OrderId = 3 }
  4. == APP == Subscriber received: Order { OrderId = 4 }
  5. == APP == Subscriber received: Order { OrderId = 5 }
  6. == APP == Subscriber received: Order { OrderId = 6 }
  7. == APP == Subscriber received: Order { OrderId = 7 }
  8. == APP == Subscriber received: Order { OrderId = 8 }
  9. == APP == Subscriber received: Order { OrderId = 9 }
  10. == APP == Subscriber received: Order { OrderId = 10 }
pubsub.yaml 组件文件

当你运行dapr init时,Dapr会创建一个默认的Redispubsub.yaml并在你的本地机器上运行一个Redis容器,它位于:

  • 在Windows上,在 %UserProfile%\.dapr\components\pubsub.yaml
  • 在Linux/MacOS上,在~/.dapr/components/pubsub.yaml

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

第3步:订阅topic

在终端窗口中,从 Quickstarts 克隆目录的根目录 导航到 order-processor 目录。

  1. cd pub_sub/java/sdk/order-processor

安装依赖项:

  1. mvn clean install

在Dapr sidecar旁边运行order-processor订阅者服务。

  1. dapr run --app-port 8080 --app-id order-processor --resources-path ../../../components -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar

order-processor 订阅者中,我们订阅名为 orderpubsub(在 pubsub.yaml 组件中定义)和topic为 orders 的 Redis 实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. @Topic(name = "orders", pubsubName = "orderpubsub")
  2. @PostMapping(path = "/orders", consumes = MediaType.ALL_VALUE)
  3. public Mono<ResponseEntity> getCheckout(@RequestBody(required = false) CloudEvent<Order> cloudEvent) {
  4. return Mono.fromSupplier(() -> {
  5. try {
  6. logger.info("Subscriber received: " + cloudEvent.getData().getOrderId());
  7. return ResponseEntity.ok("SUCCESS");
  8. } catch (Exception e) {
  9. throw new RuntimeException(e);
  10. }
  11. });
  12. }

第4步:发布topic

在新的终端窗口中,从 Quickstarts 克隆目录的根目录导航到 checkout 目录。

  1. cd pub_sub/java/sdk/checkout

安装依赖项:

  1. mvn clean install

与 Dapr sidecar 一起运行 checkout 发布者服务。

  1. dapr run --app-id checkout --resources-path ../../../components -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar

checkout发布者中,我们将orderId消息发布到名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 一旦服务启动,它就会循环发布:

  1. DaprClient client = new DaprClientBuilder().build();
  2. client.publishEvent(
  3. PUBSUB_NAME,
  4. TOPIC_NAME,
  5. order).block();
  6. logger.info("Published data: " + order.getOrderId());

第5步:查看Pub/sub输出

请注意,正如上面代码中所指定的,发布者向Dapr sidecar推送一个随机数 ,而订阅者接收它。

发布者输出:

  1. == APP == 7194 [main] INFO com.service.CheckoutServiceApplication - Published data: 1
  2. == APP == 12213 [main] INFO com.service.CheckoutServiceApplication - Published data: 2
  3. == APP == 17233 [main] INFO com.service.CheckoutServiceApplication - Published data: 3
  4. == APP == 22252 [main] INFO com.service.CheckoutServiceApplication - Published data: 4
  5. == APP == 27276 [main] INFO com.service.CheckoutServiceApplication - Published data: 5
  6. == APP == 32320 [main] INFO com.service.CheckoutServiceApplication - Published data: 6
  7. == APP == 37340 [main] INFO com.service.CheckoutServiceApplication - Published data: 7
  8. == APP == 42356 [main] INFO com.service.CheckoutServiceApplication - Published data: 8
  9. == APP == 47386 [main] INFO com.service.CheckoutServiceApplication - Published data: 9
  10. == APP == 52410 [main] INFO com.service.CheckoutServiceApplication - Published data: 10

订阅者输出:

  1. == APP == 2022-03-07 13:31:19.551 INFO 43512 --- [nio-8080-exec-5] c.s.c.OrderProcessingServiceController : Subscriber received: 1
  2. == APP == 2022-03-07 13:31:19.552 INFO 43512 --- [nio-8080-exec-9] c.s.c.OrderProcessingServiceController : Subscriber received: 2
  3. == APP == 2022-03-07 13:31:19.551 INFO 43512 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 3
  4. == APP == 2022-03-07 13:31:19.552 INFO 43512 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 4
  5. == APP == 2022-03-07 13:31:19.553 INFO 43512 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 5
  6. == APP == 2022-03-07 13:31:19.553 INFO 43512 --- [nio-8080-exec-9] c.s.c.OrderProcessingServiceController : Subscriber received: 6
  7. == APP == 2022-03-07 13:31:22.849 INFO 43512 --- [nio-8080-exec-3] c.s.c.OrderProcessingServiceController : Subscriber received: 7
  8. == APP == 2022-03-07 13:31:27.866 INFO 43512 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 8
  9. == APP == 2022-03-07 13:31:32.895 INFO 43512 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 9
  10. == APP == 2022-03-07 13:31:37.919 INFO 43512 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 10
pubsub.yaml 组件文件

当你运行dapr init时,Dapr会创建一个默认的Redispubsub.yaml并在你的本地机器上运行一个Redis容器,它位于:

  • 在Windows上,在 %UserProfile%\.dapr\components\pubsub.yaml
  • 在Linux/MacOS上,在~/.dapr/components/pubsub.yaml

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""
  13. scopes:
  14. - orderprocessing
  15. - checkout

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。

第1步:先决条件

对于此示例,您将需要:

第2步:设置环境

克隆在Quickstarts存储库中提供的示例

  1. git clone https://github.com/dapr/quickstarts.git

第3步:订阅topic

在终端窗口中,从 Quickstarts 克隆目录的根目录 导航到 order-processor 目录。

  1. cd pub_sub/go/sdk/order-processor

安装依赖项并构建应用程序:

  1. go build .

在Dapr sidecar旁边运行order-processor订阅者服务。

  1. dapr run --app-port 6005 --app-id order-processor-sdk --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run .

order-processor 订阅者中,我们订阅名为 orderpubsub(在 pubsub.yaml 组件中定义)和topic为 orders 的 Redis 实例。 这使你的应用代码能够通过 Dapr sidecar 与 Redis 组件实例通信。

  1. func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
  2. fmt.Println("Subscriber received: ", e.Data)
  3. return false, nil
  4. }

第4步:发布topic

在新的终端窗口中,从 Quickstarts 克隆目录的根目录导航到 checkout 目录。

  1. cd pub_sub/go/sdk/checkout

安装依赖项并构建应用程序:

  1. go build .

与 Dapr sidecar 一起运行 checkout 发布者服务。

  1. dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- go run .

checkout发布者中,我们将orderId消息发布到名为orderpubsub(如在pubsub.yaml组件中定义)和topic为orders的Redis实例。 一旦服务启动,它就会循环发布:

  1. client, err := dapr.NewClient()
  2. if err := client.PublishEvent(ctx, PUBSUB_NAME, PUBSUB_TOPIC, []byte(order)); err != nil {
  3. panic(err)
  4. }
  5. fmt.Println("Published data: ", order)

第5步:查看Pub/sub输出

请注意,正如上面代码中所指定的,发布者向Dapr sidecar推送一条编号消息,而订阅者接收它。

发布者输出:

  1. == APP == dapr client initializing for: 127.0.0.1:63293
  2. == APP == Published data: {"orderId":1}
  3. == APP == Published data: {"orderId":2}
  4. == APP == Published data: {"orderId":3}
  5. == APP == Published data: {"orderId":4}
  6. == APP == Published data: {"orderId":5}
  7. == APP == Published data: {"orderId":6}
  8. == APP == Published data: {"orderId":7}
  9. == APP == Published data: {"orderId":8}
  10. == APP == Published data: {"orderId":9}
  11. == APP == Published data: {"orderId":10}

订阅者输出:

  1. == APP == Subscriber received: {"orderId":1}
  2. == APP == Subscriber received: {"orderId":2}
  3. == APP == Subscriber received: {"orderId":3}
  4. == APP == Subscriber received: {"orderId":4}
  5. == APP == Subscriber received: {"orderId":5}
  6. == APP == Subscriber received: {"orderId":6}
  7. == APP == Subscriber received: {"orderId":7}
  8. == APP == Subscriber received: {"orderId":8}
  9. == APP == Subscriber received: {"orderId":9}
  10. == APP == Subscriber received: {"orderId":10}

注意:接收顺序可能会有所不同。

pubsub.yaml 组件文件

当你运行dapr init时,Dapr会创建一个默认的Redispubsub.yaml并在你的本地机器上运行一个Redis容器,它位于:

  • 在Windows上,在 %UserProfile%\.dapr\components\pubsub.yaml
  • 在Linux/MacOS上,在~/.dapr/components/pubsub.yaml

使用 pubsub.yaml 组件,您可以轻松更换底层组件而无需更改应用程序代码。

本快速入门包含的 Redis pubsub.yaml 文件包含以下内容:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: orderpubsub
  5. spec:
  6. type: pubsub.redis
  7. version: v1
  8. metadata:
  9. - name: redisHost
  10. value: localhost:6379
  11. - name: redisPassword
  12. value: ""
  13. scopes:
  14. - orderprocessing
  15. - checkout

在 YAML 文件中:

  • metadata/name 是应用程序与组件通信的方式。
  • spec/metadata定义了组件实例的连接。
  • scopes指定哪个应用程序可以使用该组件。

告诉我们您的想法

我们一直在努力改进我们的快速入门示例,并重视您的反馈。 您觉得此快速入门有帮助吗? 您有改进的建议吗?

加入我们的discord频道参与讨论。

下一步

探索 Dapr 教程 >>