Use case – Setting up an Event Subscription using the Network Manager and Event Manager

Revision for “Use case – Setting up an Event Subscription using the Network Manager and Event Manager” created on November 5, 2014 @ 16:00:51

Use case - Setting up an Event Subscription using the Network Manager and Event Manager
An important aspect when working with LinkSmart is to understand how to work with the network and how to use the LinkSmart addressing scheme together with SOAP tunnelling. Therefore we will start this section with a small use case for the usage detailing how the Network Manager is used. The actual interface definition for the Network Manager follows after this. The use case selected is that a component wants to subscribe to events from a specific Event Manager. The basic interaction steps necessary to connect to the LinkSmart network to be able to subscribe to events are: <ol> <li>Create a service endpoint: This involves registering the event consumer as a service endpoint in the LinkSmart Network Manager, i.e. getting an Virtual Address for the endpoint. As soon as there is an Virtual Address for the endpoint it is possible to invoke the service on the LinkSmart network using SOAP tunnelling.</li> <li>Find the Event Manager: This will use the methods in the Network Manager to find the Virtual Address of the Event Manager. This Virtual Address will then be used to invoke the Event Manager.</li> <li>Subscribe to events: This step uses the virtual address for the event consumer to subscribe to events. This means that all matching events (Depending on which Topics has been subscribed to) will be forwarded to the event consumer service endpoint.</li> </ol> <img class="aligncenter" src=";pgType=pgWikiAttachment&amp;ixAttachment=405&amp;sFileName=NM_EM_UseCase.png" alt="" width="305" height="442" /> The following code examples are in C# but the structure and interaction with the services looks almost the same in any language. <h2>Step 1 – Register the service endpoint</h2> The first step is to register the service endpoint for the event callback listener. In this case we assume that the service is running on the end point http://127.0.01:8345/EventCallBack.svc. <code>//Create Nework Manager client NetworkNanager.NetworkManager nm = new NetworkNanager.NetworkManager(); //First Create metadata associated with the registration, in this case only description NetworkNanager.Part a = new NetworkNanager.Part(); a.key = "DESCRIPTION"; a.value = "Exemaple:Listener"; NetworkNanager.Part c = new NetworkNanager.Part(); c.key = "PID"; c.value = "My:Unique:Event:Listener:PID"; NetworkNanager.Part[] b = new NetworkNanager.Part[2]; b[0] = a; b[1] = c; //Register the service using the attributes and the end point where the service resides NetworkNanager.Registration myreg = nm.registerService(b, "http://127.0.01:8345/EventCallBack.svc", "");</code> Note that we only add one attribute to describe the Virtual Address, the DESCRIPTION. It is possible to add more attributes that can be useful for determining the type of service etc. All these attributes can be used when invoking the search functions of the Network Manager. <h2>Step 2 – Find the Virtual Address</h2> The second step is to find the Virtual Address Event Manager that we want to subscribe to using the Networks Managers search functionality. <code>string emDesc = "EventManager:INCERPI"; NetworkNanager.Registration[] r= nm.getServiceByDescription(emDesc);</code> In this case we identified the service only by it description “EventManager:INCERPI”. It is important to realize that this service can exist anywhere in the LinkSmart network and it is completely transparent for the client. <h2>Step 3 – Set up a subscription</h2> The final step is to call the Event Manager to setup a subscription to the service registered in the first step. <code>//Example of SOAPtunneling EventManager.EMImplementation em = new EventManager.EMImplementation(); string vid = r[0].virtualAddressAsString; &nbsp; //Set the Event Managers client endpoint to the SOAP tunnel address em.Url = string.Format("{0}/", vid); &nbsp; //Set up the subscription, listening to the to what the xPath expression matches string xpath = "//[local-name()='IoTEntity']"; em.subscribeXPathWithPID(xpath, "My:Unique:Event:Listener:PID", 0);<code> Note that we use the Virtual Address created for our event callback listener service when subscribing. This will allow the Event Manager to publish events to us even if we are in a completely different network.

OldNewDate CreatedAuthorActions
November 5, 2014 @ 16:00:51 Vivian Esquivias
November 5, 2014 @ 15:58:50 Vivian Esquivias