3

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?

Goblin
  • 7,970
  • 3
  • 36
  • 40

1 Answers1

8

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

Marijn
  • 10,367
  • 5
  • 59
  • 80
juanagui
  • 807
  • 9
  • 8
  • Thanks! I'll have to try that out :-). – Goblin Nov 13 '11 at 09:24
  • I got it working! Thanks a lot man - seems there has been some developement in the project lately. Just getting it on NuGet was a huge help. Plus Ayende's last articles helped too. – Goblin Dec 18 '11 at 20:36
  • I think you mean [this article](http://ayende.com/blog/140289/setting-up-a-rhino-service-bus-application-part-iindash-one-way-bus) – Marijn Oct 26 '12 at 12:21