我正在编写一个持久的实体函数,该函数需要像Azure Service Bus(onMessageCallback)一样回调客户端(asp.net核心应用程序)?
此刻,客户端发送带有回调URL的请求。
public class ThrottlerClient : IThrottlerClient
{
private readonly ISecurityTokenFactory _securityTokenFactory;
private readonly HttpClient _client;
private string _completeHandlerUrl;
private string _errorHandlerUrl;
private string _receiveUrl;
public ThrottlerClient(HttpClient client, ISecurityTokenFactory securityTokenFactory)
{
_client = client;
_securityTokenFactory = securityTokenFactory;
_receiveUrl = Environment.GetEnvironmentVariable("Throttler:ReceiveUrl");
_completeHandlerUrl = Environment.GetEnvironmentVariable("Throttler:CompleteHandlerUrl");
_errorHandlerUrl = Environment.GetEnvironmentVariable("Throttler:ErrorHandlerUrl");
}
public async Task<string> Send(ICommand command, string submittedByName, string partitionKey)
{
var throttledRequest = new ThrottledRequest(command, submittedByName, partitionKey)
{
CompleteHandlerUrl = _completeHandlerUrl,
ErrorHandlerUrl = _errorHandlerUrl
};
var token = _securityTokenFactory.Create($"{nameof(ThrottlerClient)}");
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{token}");
await _client.PostAsync(_receiveUrl, throttledRequest);
return throttledRequest.CorrelationId;
}
}
希望改善该实现。想知道是否有人知道它是如何实现的,或者可以向我介绍一些文档。