Is it possible to run Orleans hosted within Windows Service
Asked Answered
H

1

8

Please, point me out if there are any direct methods to run Orleans hosted within Windows Service. If there are no direct methods, then are there any indirect methods of doing that?

Thank you in advance

Hellhole answered 28/4, 2016 at 21:43 Comment(2)
are you looking to not write any code?Hosier
@BozoJoe, actually yes. But as per my knowledge there is no built-in feature for that. I also paid more attention to the test/dev host project in visual studio and it seems to me now that the code will be pretty the same as the one used to run Orleans within the same process in the additional AppDomain.Hellhole
H
8

Note: this is for v1.x Orleans. 2.x configuration changed quite a bit

Here's a topshelf based sample. referencing https://github.com/migrap/Topshelf.Orleans

static void Main()
{
    HostFactory.Run(c => {
        c.Service<OrleansService>(s => {
            s.ConstructUsing(sc => {
                sc.ConfigFileName("OrleansConfiguration.xml");

                //do some config at runtime if you want
                //sc.DeploymentId("blachblahc");

            });

            s.WhenStarted((service, control) => service.Start());
            s.WhenStopped((service, control) => service.Stop());
        });

        c.RunAsLocalSystem();
        c.UseAssemblyInfoForServiceInfo();
        c.SetServiceName("OrleansSiloHostService");
        c.StartAutomaticallyDelayed();
    });
}

public class OrleansService
{
    private readonly SiloHost host;
    private Task startup;

    internal OrleansService(SiloHost silohost)
    { host = silohost; }

    public bool Start()
    {
        host.LoadOrleansConfig();
        host.InitializeOrleansSilo();
        startup = Task.Factory.StartNew(() =>
        {
            return host.StartOrleansSilo();
        });
        return true;
    }

    public bool Stop()
    {
        if (startup.Status == TaskStatus.RanToCompletion)
        { host.ShutdownOrleansSilo(); }
        return true;
    }
}
Hosier answered 30/4, 2016 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.