在asp中订阅dapr的消息队列 #4

Closed
opened 2 years ago by Sirius · 0 comments
Sirius commented 2 years ago
Owner

ASP有植入式的SDK.

  1. Program.cs中, app.MapControllers()之前:
app.UseCloudEvents();
app.MapSubscribeHandler();

如果不加UseCloudEvents()也会订阅成功, 但在Controller中解不出参数.

  1. Controller中的方法上添加[Topic("{消息borker名称}", "{Topic/Channel}")]

其中消息broker名称是组件描述pubsub.yaml文件中指定的那个

metadata:
  name: {消息borker名称}

跟配置状态存储的名称类似

  1. 方法跟ASP的正常API方法一样, 同一个方法可以既作为API方法又作为订阅方法
[Topic("{消息borker名称}", "{Topic/Channel}")]
[HttpPost]
public async Task ServerPost([FromBody] 参数类型 参数名)
{
}
ASP有植入式的SDK. 1. 在`Program.cs`中, `app.MapControllers()`之前: ```csharp app.UseCloudEvents(); app.MapSubscribeHandler(); ``` 如果不加`UseCloudEvents()`也会订阅成功, 但在`Controller`中解不出参数. 2. 在`Controller`中的方法上添加`[Topic("{消息borker名称}", "{Topic/Channel}")]` 其中消息broker名称是组件描述`pubsub.yaml`文件中指定的那个 ```yaml metadata: name: {消息borker名称} ``` 跟配置状态存储的名称类似 3. 方法跟ASP的正常API方法一样, 同一个方法可以既作为API方法又作为订阅方法 ```csharp [Topic("{消息borker名称}", "{Topic/Channel}")] [HttpPost] public async Task ServerPost([FromBody] 参数类型 参数名) { } ```
Sirius added the
dotnet
label 2 years ago
Sirius closed this issue 2 years ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Sirius/note#4
Loading…
There is no content yet.