0

I'm going to use a third party messaging system to receive the messages for my stateful service. So I started to look at the ICommunicationListener interface and existing samples. However, it's unclear what it should do since most examples processes inbound messages directly or indirectly in the communication listener. I can't find any way to pass inbound messages to the service.

Because of that, I can't find any meaningful reason to why the ICommunicationListener interface or the CreateServiceReplicaListeners method exists. The service itself already have all knowledge about how to create and configure the listeners. Thus your could just configure your own listener directly in the stateful service (using composition) without being forced to implement a specific interface.

So what do the additional layer of complexity add?

jgauffin
  • 99,844
  • 45
  • 235
  • 372

2 Answers2

0

Here's an example of a custom implementation of ICommunicationListener. I pass in an instance of IServiceBusMessageReceiver that handles incoming messages.

LoekD
  • 11,402
  • 17
  • 27
  • .. and your example perfectly illustrate my point. There is no need for the `ICommunicationListener` interface. Thus you are not really answering my question. – jgauffin Apr 03 '17 at 14:26
  • 1
    It's about separation of concerns, you disconnect the comms channel from the methods that handle incoming requests. So the service doesn't need to change if messages come in from another /addtitonal source. You can have multiple channels too. – LoekD Apr 03 '17 at 14:32
  • It do need to change. It need to include the new listener. I specifically stated ***composition*** in my question. With composition the changes for new communication methods are still minimal. Regarding start/stop for the listener. will they ever be invoked unless the services is started/stopped? – jgauffin Apr 05 '17 at 06:09
  • yes, either when you need it to stop (like in a custom active / passive setup) or when a service replica is promoted from non-listening secondary to listening primary or v.v.. – LoekD Apr 05 '17 at 07:48
  • But those changes are applied to the service itself too, right? – jgauffin Apr 05 '17 at 08:19
  • I mean that the lifespan of the communication listener is not tied to the lifespan of the service. – LoekD Apr 14 '17 at 10:13
  • Is that documented anywhere? In which scenarions are they different? – jgauffin Apr 14 '17 at 12:59
0

I also struggled with this. In my opinion name of ICommunicationListener is misleading in that it isn't really the "thing" that does the listening/communication in most cases. However it abstracts the functionality and defines methods to Start, Shutdown, and Abort the actual communication channel. This allows the Service Fabric Service to startup and shutdown independent of the actual communication channel. It also allows the communication channel to shutdown gracefully in the event the service shuts down abruptly.

Maybe not an answer but it was to long for a comment.

Tony
  • 1,297
  • 10
  • 17