使用Rebus分散/聚集

使用Rebus分散/聚集,rebus,Rebus,我需要在接收到出现在(MSMQ)队列中的单个消息时批处理多个web服务调用 “传奇”是一条路吗 与第三方web服务的交互更加复杂,因为我需要调用它一次,然后在对web服务的初始调用的回复中返回一个相关id,随后进行轮询以获得确认。是的,sagas可能是协调发起调用过程的方法,轮询直到操作结束,然后在所有工作完成后执行其他操作 如果您不太在意不小心多次调用web服务,那么您可以轻松地使用Rebus的async功能来实现轮询-我目前正在构建一些基本上可以做到这一点的东西: public async

我需要在接收到出现在(MSMQ)队列中的单个消息时批处理多个web服务调用

“传奇”是一条路吗


与第三方web服务的交互更加复杂,因为我需要调用它一次,然后在对web服务的初始调用的回复中返回一个相关id,随后进行轮询以获得确认。

是的,sagas可能是协调发起调用过程的方法,轮询直到操作结束,然后在所有工作完成后执行其他操作

如果您不太在意不小心多次调用web服务,那么您可以轻松地使用Rebus的
async
功能来实现轮询-我目前正在构建一些基本上可以做到这一点的东西:

public async Task Handle(SomeMessage message)
{
    var response = await _client.Get<SomeResponse>("https://someurl")   ;
    var pollUrl = response.PollUrl;
    var resultUrl = response.ResultUrl;

    while(true)
    {
        var result = await _client.Get<PollResult>(pollUrl);

        if (result.Status == PollStatus.Processing)
        {
            await Task.Delay(TimeSpan.FromSeconds(2));
            continue;
        }

        if (result.Status == PollStatus.Done)
        {
            var finalResult = await _client.Get<FinalResult>(resultUrl);

            return new SomeReply(finalResult);;
        }

        throw new Exception($"Unexpected status while polling {pollUrl}: {result.Status}")
    }
}
公共异步任务句柄(SomeMessage)
{
var response=wait_client.Get(“https://someurl")   ;
var pollUrl=response.pollUrl;
var resultur=response.resultur;
while(true)
{
var result=wait_client.Get(pollUrl);
if(result.Status==PollStatus.Processing)
{
等待任务延迟(时间跨度从秒(2));
继续;
}
if(result.Status==PollStatus.Done)
{
var finalResult=wait _client.Get(resultur);
返回新的SomeReply(finalResult);;
}
抛出新异常($“轮询{pollUrl}时的意外状态:{result.status}”)
}
}

因此,利用
async
/
wait
在外部Web服务处理过程中轮询外部Web服务,同时消耗最少的资源。

是的,sagas可以协调发起调用的过程,轮询直到操作结束,当所有的工作都完成后,再做些别的事情

如果您不太在意不小心多次调用web服务,那么您可以轻松地使用Rebus的
async
功能来实现轮询-我目前正在构建一些基本上可以做到这一点的东西:

public async Task Handle(SomeMessage message)
{
    var response = await _client.Get<SomeResponse>("https://someurl")   ;
    var pollUrl = response.PollUrl;
    var resultUrl = response.ResultUrl;

    while(true)
    {
        var result = await _client.Get<PollResult>(pollUrl);

        if (result.Status == PollStatus.Processing)
        {
            await Task.Delay(TimeSpan.FromSeconds(2));
            continue;
        }

        if (result.Status == PollStatus.Done)
        {
            var finalResult = await _client.Get<FinalResult>(resultUrl);

            return new SomeReply(finalResult);;
        }

        throw new Exception($"Unexpected status while polling {pollUrl}: {result.Status}")
    }
}
公共异步任务句柄(SomeMessage)
{
var response=wait_client.Get(“https://someurl")   ;
var pollUrl=response.pollUrl;
var resultur=response.resultur;
while(true)
{
var result=wait_client.Get(pollUrl);
if(result.Status==PollStatus.Processing)
{
等待任务延迟(时间跨度从秒(2));
继续;
}
if(result.Status==PollStatus.Done)
{
var finalResult=wait _client.Get(resultur);
返回新的SomeReply(finalResult);;
}
抛出新异常($“轮询{pollUrl}时的意外状态:{result.status}”)
}
}
因此,利用
async
/
wait
在外部Web服务处理时轮询外部Web服务,同时消耗最少的资源