Topshelf multiple host
Asked Answered
E

2

5

Is there any way in topshelf to run multiple host in one executable?

// Create hosts
var h1 = HostFactory.New (...); var h2 = HostFactory.New (...)

// Start hosts
 in one application Runner.Run (h1, h2);

Edit

Solved with threads. But not sure if it is safe...

new Thread (()=>Runner.Run (h1));    
new Thread (()=>Runner.Run (h2));
Expostulate answered 9/2, 2012 at 22:31 Comment(1)
So this could cause a lot of a problems, I'm not sure the ServiceCoordinator is addressable safely like this, you might get cross talk between them. Also, this will have odd behaviour if you attempt to run it as a service and not just a console App. I wouldn't suggest this approach at all. If you want some more ideas, join our mailing list groups.google.com/forum/#!forum/topshelf-discussMountebank
M
1

Note: This is only valid for pre-3.0 version of Topshelf. In 3.0 this was removed and is being replaced with other methods of hosting multiple services.

There is no way to run multiple hosts. Starting a host blocks execution, does a whole bunch of stuff. You can register multiple logical services in a single host though.

https://github.com/Topshelf/Topshelf/wiki/Creating-a-service

return (int)HostFactory.Run(x => {
  x.Service<Service1>({ ... });
  x.Service<Service2>({ ... ]);
}); 

All logical services run under a single AppDomain. This may or may not be an issue. If you need to host them in separate AppDomains, we started working on shelving. http://topshelf-project.com/documentation/shelving/ As a warning, if you're going to start multiple logical services with the same type, make sure they have unique names when configured.

Mountebank answered 10/2, 2012 at 11:38 Comment(3)
As of 3.0, multiple services are not supported in this manner.Marrymars
You say "in this manner". Is there any other way as of now ? I upgraded topshelf for trouble with Lognet 1.2.11 , only to see that this feature ( and the complete DSL for that matter) are gone or changed :sSaxton
How can we do this in TopShelf 3.0?Loos
M
10

From Topshelf docs:

You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services. This was done because the code to implement was very brittle and hard to debug. We have opted for a simpler and cleaner base product. This feature will most likely come back in the form of an add on nuget.

Myramyrah answered 5/9, 2014 at 15:45 Comment(0)
M
1

Note: This is only valid for pre-3.0 version of Topshelf. In 3.0 this was removed and is being replaced with other methods of hosting multiple services.

There is no way to run multiple hosts. Starting a host blocks execution, does a whole bunch of stuff. You can register multiple logical services in a single host though.

https://github.com/Topshelf/Topshelf/wiki/Creating-a-service

return (int)HostFactory.Run(x => {
  x.Service<Service1>({ ... });
  x.Service<Service2>({ ... ]);
}); 

All logical services run under a single AppDomain. This may or may not be an issue. If you need to host them in separate AppDomains, we started working on shelving. http://topshelf-project.com/documentation/shelving/ As a warning, if you're going to start multiple logical services with the same type, make sure they have unique names when configured.

Mountebank answered 10/2, 2012 at 11:38 Comment(3)
As of 3.0, multiple services are not supported in this manner.Marrymars
You say "in this manner". Is there any other way as of now ? I upgraded topshelf for trouble with Lognet 1.2.11 , only to see that this feature ( and the complete DSL for that matter) are gone or changed :sSaxton
How can we do this in TopShelf 3.0?Loos

© 2022 - 2024 — McMap. All rights reserved.