3
public static void SendREsbDx(Job job)
{
    using (var adapter = new BuiltinContainerAdapter())
    {
        adapter.Handle<ReplyMsg>(msg =>
        {
            string mss = msg.message;
        });

        Configure.With(adapter)
            .Logging(l => l.ColoredConsole(LogLevel.Warn))
            .MessageOwnership(o => o.FromRebusConfigurationSection())
            .Transport(t => t.UseSqlServer("server=.;initial catalog=rebus_test;integrated security=true","consumerx","error")
                             .EnsureTableIsCreated())
            .CreateBus()
            .Start();
        adapter.Bus.Send<Job>(job);
    }
}

上記のコードを使用して、消費者にメッセージを送信しています。コンシューマーは bus.Reply を使用しますが、上記のコードは明らかに機能しません。

消費者からの返信を受け取りたいだけです。これはどのように達成されますか?

4

1 に答える 1

3

Jobコンシューマーにはメッセージのハンドラーがないようです。

あなたの場合、2つのバスインスタンスが必要になるように思えます. which willの実装を持つコンシューマーインスタンスと、 which IHandleMessages<Job>willの実装を持つbus.Reply(new ReplyMsg {...})プロデューサーインスタンスで、応答ハンドラーで実行する必要があることは何でも実行します。IHandleMessages<ReplyMsg>bus.Send(new Job{...})

要求/応答を示すサンプル コードに興味がある場合は、Rebus サンプル リポジトリにある統合サンプルを参照してください。これには、クライアント間で単純な要求/応答が行われています (これは、クライアントのプロデューサーに対応します)。ケース) および IntegrationService (コンシューマーに対応)。

次のコード スニペットは、その方法を示しています。

var producer = new BuiltinContainerAdapter();
var consumer = new BuiltinContainerAdapter();

consumer.Handle<Job>(job => {
    ...
    consumer.Bus.Reply(new ReplyMsg {...});
});

producer.Handle<ReplyMsg>(reply => {
    ....
});

Configure.With(producer)
     .Transport(t => t.UseSqlServer(connectionString, "producer.input", "error")
                      .EnsureTableIsCreated())
     .MessageOwnership(o => o.FromRebusConfigurationSection())
     .CreateBus()
     .Start();

Configure.With(consumer)
     .Transport(t => t.UseSqlServer(connectionString, "consumer.input", "error")
                      .EnsureTableIsCreated())
     .MessageOwnership(o => o.FromRebusConfigurationSection())
     .CreateBus()
     .Start();

// for the duration of the lifetime of your application
producer.Bus.Send(new Job {...});


// when your application shuts down:
consumer.Dispose();
producer.Dispose();

Jobapp.config には、次の場所にマップするエンドポイント マッピングが必要ですconsumer.input

<rebus>
    <endpoints>
         <add messages="SomeNamespace.Job, SomeAssembly" endpoint="consumer.input"/>
    </endpoints>
</rebus>

コードが機能しない理由がわかったと思います。さらに詳しく説明する必要がある場合はお知らせください:)

上記のコードが実際に実行できることを証明するために、リクエスト/リプライのサンプルRebus サンプル リポジトリに追加しました(....もちろん、etc を削除した場合 - このコードを使用するには C# の基本的な理解が必要です)。 )

于 2014-10-19T10:59:07.297 に答える