質問
私は多くの例/チュートリアルを読みました(MSDNのAyendeのアレクサンドリアを含む)。
しかし、やや更新されたアセンブリを取得するだけで、それ自体が障害であることが証明されています。 Castle.Windsorの正しいバージョンを取得した後 - app.configファイルに正しいセクションが見つかりません。 RhinoサービスバスとCastleBootstrapperの両方の構文も変更されました - そして、私は今では完全に混乱しています。冬眠ライノの「ドキュメンテーション」は、私が始めるのを本当に助けていません。
Castle Windsorv。3.0(ベータ)または2.5.3を備えたRhino Service Busを使用して、Rhino Service Busを使用して作業サンプルを手伝っていただけませんか。アップアンドランニング?
解決
Github(https://github.com/hibernating-rhinos/rhino-esb)から最新のRhino-ESBビットをダウンロードして、それを構築した後、開始するのは非常に簡単です。
Rhino-ESBを介してバックエンドと通信するASP.NET MVCアプリケーションがあります。
ASP.NET MVC側:
global.asax.cs:
private IWindsorContainer _container;
protected void Application_Start()
{
_container = new WindsorContainer();
new RhinoServiceBusConfiguration().UseCastleWindsor(_container).Configure();
_container.Install(new YourCustomInstaller());
//Don't forget to start the bus
_container.Resolve<IStartableServiceBus>().Start();
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container));
}
ご了承ください YourCustomInstaller
実装する必要があります IWindsorInstaller
そして、あなたはあなたのコントローラーをのコンテナに登録します Install
方法:
public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
container.Register(Component
.For<HomeController>().LifeStyle.PerWebRequest.ImplementedBy<HomeController>());
また、に注意してください WindsorControllerFactory
内部的にコントローラーの作成をコンテナに委任します。
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
return null;
return (IController)this.container.Resolve(controllerType);
}
最後になりましたが、web.configで構成を提供します
<configSections>
<section name="rhino.esb" type="Rhino.ServiceBus.Config.BusConfigurationSection, Rhino.ServiceBus"/>
</configSections>
<rhino.esb>
<bus threadCount="1"
numberOfRetries="5"
endpoint="rhino.queues://localhost:31316/Client"
queueIsolationLevel="ReadCommitted"
name="Client"/>
<messages>
<add name="YourMessagesNamespace"endpoint="rhino.queues://localhost:31315/Backend"/>
</messages>
</rhino.esb>
この構成は、バックエンドがlocalhost:31315でキューを実行し、クライアントがlocalhost:31316でキューを実行することを想定しています。
バックエンド側:コンソールアプリケーションとして実行していると仮定すると、
static void Main(string[] args)
{
IWindsorContainer container;
container = new WindsorContainer();
new RhinoServiceBusConfiguration()
.UseCastleWindsor(container)
.Configure();
var host = new RemoteAppDomainHost(typeof(YourBootstrapper));
host.Start();
Console.WriteLine("Starting to process messages");
Console.ReadLine();
それに注意してください YourBootstrapper
クラスの実装 CastleBootstrapper
public class YourBootstrapper: Rhino.ServiceBus.Castle.CastleBootStrapper
{
protected override void ConfigureContainer()
{
Container.Register(Component.For<OneOfYourMessages>());
}
}
その中で消費者を登録しています OneOfYourMessages