开发者

Getting started with rhino service bus

I've read a lot of examples/tutorials (incl. Ayende's Alexandria on MSDN).

But just getting somewhat updated assemblies have proven to be an obstacle in itself. After getting the correct version of Castle.Windsor - it cannot find the correct section in the app.config 开发者_开发百科file. The syntax in both Rhino Service Bus and the CastleBootstrapper has been changed as well - and I'm now totally confused. The 'documentation' on Hibernating Rhinos is really not helping me get started.

Could anyone please help me a working sample with Rhino Service Bus with either Castle Windsor v. 3.0 (beta) or 2.5.3, point me at something already online or just giving me a step-by-step pointers on what I need to get up and running?


after downloading the latest Rhino-ESB bits from github (https://github.com/hibernating-rhinos/rhino-esb) and building it, it's pretty straightforward to get started.

I have a asp.net MVC application which communicates with a backend through Rhino-ESB.

On the asp.net MVC side:

On 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));
}

Note that YourCustomInstaller must implement IWindsorInstaller and you register your controllers with the container in the Installmethod:

public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
    container.Register(Component
       .For<HomeController>().LifeStyle.PerWebRequest.ImplementedBy<HomeController>());

Also note that the WindsorControllerFactory internally delegates controller creation to the container:

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

Last but not least, provide the configuration on your 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>

This configuration assumes that the backend runs a queue in localhost:31315 and the client runs its queue on localhost:31316.

On the backend side: assuming we're running it as a console application,

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();

Notice that YourBootstrapperclass implements CastleBootstrapper

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

in which we're registering a consumer for OneOfYourMessages

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜