开始使用rhino服务总线

Gob*_*lin 3 rhino-servicebus

我已经阅读了很多示例/教程(包括在MSDN上的Ayende的Alexandria).

但是,仅仅获得一些更新的组件本身已被证明是一个障碍.获取Castle.Windsor的正确版本后 - 它无法在app.config文件中找到正确的部分.Rhino Service Bus和CastleBootstrapper中的语法也发生了变化 - 我现在完全感到困惑.关于Hibernating Rhinos的'文档'实际上并没有帮助我开始.

有没有人可以帮我一个Rhino Service Bus的工作样本,使用Castle Windsor v.3.0(测试版)或2.5.3,指点我已经在线的东西,或者只是给我一步一步指出我需要得到什么启动并运行?

jua*_*gui 8

从github(https://github.com/hibernating-rhinos/rhino-esb)下载最新的Rhino-ESB位并构建它之后,开始就非常简单了.

我有一个asp.net MVC应用程序,它通过Rhino-ESB与后端通信.

在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));
}
Run Code Online (Sandbox Code Playgroud)

请注意,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>());
Run Code Online (Sandbox Code Playgroud)

另请注意,WindsorControllerFactory内部委托控制器创建到容器:

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        if (controllerType == null)
            return null;
        return (IController)this.container.Resolve(controllerType);
    }
Run Code Online (Sandbox Code Playgroud)

最后但并非最不重要的是,在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>
Run Code Online (Sandbox Code Playgroud)

此配置假定后端在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();
Run Code Online (Sandbox Code Playgroud)

请注意,YourBootstrapper类实现CastleBootstrapper

public class YourBootstrapper: Rhino.ServiceBus.Castle.CastleBootStrapper
    {
        protected override void ConfigureContainer()
        {
            Container.Register(Component.For<OneOfYourMessages>());
        }
    }
Run Code Online (Sandbox Code Playgroud)

我们在其中注册消费者 OneOfYourMessages