开始使用rhino服务总线

时间:2011-09-08 10:34:51

标签: rhino-servicebus

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

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

有没有人可以帮我一个Rhino Service Bus的工作样本,使用Castle Windsor v.3.0(beta)或2.5.3,指点我已经在线的东西或只是给我一步一步的指示我需要起床和跑步?

1 个答案:

答案 0 :(得分: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));
}

请注意,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

注册消费者
相关问题