[en] Windows Service (solved)

Topics: Technical Support
Oct 25, 2016 at 10:34 AM
Edited Oct 25, 2016 at 3:06 PM
I'm considering Zyan, and I have a few questions.

1) Can I have a Windows Service (an instance of a class derived from System.ServiceProcess.ServiceBase) instantiated on the server-side and implementing a shared interface act as a singleton service? Can I register it as a Component?

2) Can the service raise events independently of any client requests? For instance, a non-Zyan event is raised in the service from some other source, and then the server raises a Zyan event to be handled by clients?

3) If I have a decentralized system where, let's say, clients C1 and C2 are registered to receive events from server S1, and clients C3 and C4 are receiving events from server S2, and let's say that a Disconnect event (if there is one) is received by clients C1 and C2 because S1 has gone down, is it currently possible for those clients to switch over to getting events from S2?

4) Does Zyan work like a message queue, such as in RabbitMQ? It seems more synchronous than that, but I just want to check.


5) If I recall correctly, Zyan has some sort of Disconnect event that is raised when a heart beat polling feature fails to find the server. Is that correct? I might be misremembering and thinking of some other framework. If this doesn't exist, how easy is it to implement?
Oct 26, 2016 at 2:44 AM
Edited Nov 19, 2016 at 9:19 PM
Hello Mark,

1) Yes, you can. I've just created an example for you:

It boils down to this:
// Service class
public class ServiceExample : ServiceBase, IServiceExample
    private ZyanComponentHost Host { get; set; }

    protected override void OnStart(string[] args)
        // start the server
        Host = new ZyanComponentHost(name, port);
        Host.RegisterComponent<IServiceExample, ServiceExample>(this);

    protected override void OnStop()
        // stop the server

    // implement your shared interface here
But I'd suggest to use the TopShelf library instead of ServiceBase.
To my experience, it's a lot easier to set up and maintain (no installutil required, etc.)
Here is an example Zyan+TopShelf service: https://gist.github.com/yallie/7a3a4a16ce8f4b9e74da

2) Yes, surely.

3) Yes, that's possible. To receive events from another server, C1 and C2 should
connect to server S2 and subscribe to its events manually, just as they did to server S1.
Also, you can have your S1 and S2 servers to subscribe to each other's events and
rebroadcast them to their clients (this feature isn't included out-of-the-box, but it's easy
to implement).

4) No, Zyan isn't an message queue, it's an RPC. It supports pub-sub pattern,
but it doesn't have persistent queues, guaranteed event delivery and such.

5) Yes, ZyanConnection class has Disconnected event (it works if heartbeat is enabled).
Disconnected event allows to retry or cancel the connection. If retrying succeeded,
the Reconnected event is raised.

Here is the checklist for these events: https://zyan.codeplex.com/discussions/573430
And here is the complete sample: https://gist.github.com/yallie/437ea4c087725693e1c2

Hope that helps,