UnSubscribe to a service
If a service drops, if I send a drop message to all of the services that I subscribed to, how can I then send a notice to the subscribe manager to let it know that the service has dropped and is no longer partnered?
If a service drops, if I send a drop message to all of the services that I subscribed to, how can I then send a notice to the subscribe manager to let it know that the service has dropped and is no longer partnered?
Before sending the subscribe request, specify a ShutDown port for the subscribe message. For example the Simple Dashboard does it like this:
Port<Shutdown> _motorShutdown = null;
IEnumerator<ITask> OnConnectMotorHandler(OnConnectMotor onConnectMotor)
{
_motorShutdown = new Port<Shutdown>();
drive.
Subscribe subscribe = new drive.Subscribe( new SubscribeRequestType());
subscribe.NotificationPort = _driveNotify;
subscribe.NotificationShutdownPort = _motorShutdown;
_drivePort.Post(subscribe);
yield return Arbiter.Choice(
subscribe.ResponsePort,
delegate(SubscribeResponseType response)
{
LogInfo("Subscribed to " + onConnectMotor.Service);
},
delegate(Fault fault)
{
_motorShutdown = null;
LogError(fault);
}
);
}
And whenever you wanted to unsubscribe, simply post a message to the ShutDown port.
void DropHandler(DsspDefaultDrop drop)
{
PerformShutdown(
ref _motorShutdown); base.DefaultDropHandler(drop);}
void PerformShutdown(ref Port<Shutdown> port)
{
if (port == null)
return;
Shutdown shutdown = new Shutdown();
port.Post(shutdown);
port = null;
}
After looking at it some more, I still have a question.
Before, I just thought that the port.Post(shutdown) did something to automatically remove the subscription, but now I'm wondering how this happens.
In your example, how does the Motor service get the message? The Motor service doesn't have a receiver for a Shutdown message or anything. How could the Motor service's subscription manager know about this shutdown post?
Thanks,
Don
Hi Don. You are correct.
During the post of the subscription, the service forwarder infrastructure understands the subscription action and adds an Activation on the port you provided (_motorShutdown). When you post a Shutdown message to that port, the infrastructure takes care of removing your subscription entry from the subscription manager. All of this happens in the context of your service, as if you had done the activation yourself.
subscribe.NotificationPort = _driveNotify;
subscribe.NotificationShutdownPort = _motorShutdown;
_drivePort.Post(subscribe);
David
Don, as David said the runtime is taking care of the activation. You can see the activation in reflector by looking at CreateSubscribeTarget method in DssRuntime.dll::Microsoft.Dss.Services.Forwarders.Dssp.DsspForwarder.
Omid