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?

[225 byte] By [Don] at [2008-3-3]
# 1

Before sending the subscribe request, specify a ShutDown port for the subscribe message. For example the Simple Dashboard does it like this:

Code Snippet

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.

Code Snippet

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;

}

OmidK.Rad at 2007-9-25 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Decentralized Software Services (DSS)...
# 2
Thank you!
Don at 2007-9-25 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Decentralized Software Services (DSS)...
# 3

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

Don at 2007-9-25 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Decentralized Software Services (DSS)...
# 4

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.

Code Snippet

subscribe.NotificationPort = _driveNotify;

subscribe.NotificationShutdownPort = _motorShutdown;

_drivePort.Post(subscribe);

David

DaveLee at 2007-9-25 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Decentralized Software Services (DSS)...
# 5

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.

Code Snippet
private void CreateSubscriptionTarget(DsspOperation Sub, ForwarderEnvelope env) { ... if (subOp.NotificationShutdownPort != null) { Receiver<Shutdown>[] CS$0$0004 = new Receiver<Shutdown>[] { Arbiter.Receive<Shutdown>(false, subOp.NotificationShutdownPort, delegate (Shutdown S) { this.DeleteSubscription(body.Subscriber); }) }; base.Activate<Receiver<Shutdown>>(CS$0$0004); } ...}

Omid

OmidK.Rad at 2007-9-25 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Decentralized Software Services (DSS)...
# 6

Ah, thank you both very much, that's what I originally thought happened.

Don at 2007-9-25 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Decentralized Software Services (DSS)...

Microsoft Robotics Studio

Site Classified