8

次のサービスがあります

public class AppService : AsyncServiceBase<EvaluateStock>
{
    public IBus Bus { get; set; }

    public override object ExecuteAsync(EvaluateStock request)
    {
        // this will block the incoming http request 
        // unitl task is completed

        // long computation
        // Bus.Publish(result)
    }
}

次の方法でさまざまな消費者によって呼び出されます

POST
http://srv1/app/json/asynconeway/EvaluateStock

asynconeway を使用すると、WCF が IsOneWay で行うように、火をつけて忘れることができると想定していました。しかし、そうではないようです。

私は何かが恋しいですか?

4

1 に答える 1

8

ExecuteAsyncが ServiceBase に含まれるようになったため、AsyncServiceBaseは非推奨になりました。これは、 /asynconeway/XXXの事前定義されたエンドポイントに対して要求が行われたときに呼び出されるものです。

ExecuteAsyncをオーバーライドするのではなく、AppHost IOC に が登録されている場合に呼び出されるIMessageFactoryを実装することをお勧めします。IMessageFactoryIMessageFactory が登録されていない場合は、Sync が実行されるだけです。この時点で、非ブロッキングが必要な場合はオーバーライドします。ExecuteAsync の impl は次の場所にあります。

// Persists the request into the registered message queue if configured, 
// otherwise calls Execute() to handle the request immediately.
// 
// IAsyncService.ExecuteAsync() will be used instead of IService.Execute() for 
// EndpointAttributes.AsyncOneWay requests
public virtual object ExecuteAsync(TRequest request)
{
    if (MessageFactory == null)
    {
        return Execute(request);
    }

    BeforeEachRequest(request);

    //Capture and persist this async request on this Services 'In Queue' 
    //for execution after this request has been completed
    using (var producer = MessageFactory.CreateMessageProducer()) {
        producer.Publish(request);
    }

    return ServiceUtils.CreateResponseDto(request);
}

IMessageFactory (クライアント)/IMessageService (サーバー) は ServiceStack の Messaging API の一部であり、後で実行を延期するためにメッセージを公開できます。組み込みの Redis IMessageService を使用するエンド ツー エンド ソリューションの例については、 Redis and Messaging wikiを参照してください。InMemoryRConの IMesssageServiceも利用可能で、独自のものを簡単に作成できるはずです。

将来の非同期サポート

ServiceStack が実行されている非同期ブランチもありIHttpAsyncHandler、機能するアルファ ビルドが既にあり、試用できます: ServiceStack-v4.00-alpha.zip

この変更により、ServiceStack はTask<>サービスの戻り値の型としてサポートされます。Task<> プラグインを登録するだけです。完全な例を見るには、この統合テストを見てください。

于 2012-06-20T18:42:00.520 に答える