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

Wikis > LinkSmart.net > Network Manager > 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:

  1. 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.
  2. 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.
  3. 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.

The following code examples are in C# but the structure and interaction with the services looks almost the same in any language.

Step 1 – Register the service endpoint

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.

//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", "eu.linksmart.network.backbone.impl.soap.BackboneSOAPImpl");

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.

Step 2 – Find the Virtual Address

The second step is to find the Virtual Address Event Manager that we want to subscribe to using the Networks Managers search functionality.

string emDesc = "EventManager:INCERPI";

NetworkNanager.Registration[] r= nm.getServiceByDescription(emDesc);

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.

Step 3 – Set up a subscription

The final step is to call the Event Manager to setup a subscription to the service registered in the first step.

//Example of SOAPtunneling

EventManager.EMImplementation em = new EventManager.EMImplementation();

string vid = r[0].virtualAddressAsString;

 

//Set the Event Managers client endpoint to the SOAP tunnel address

em.Url = string.Format("http://127.0.0.1:8082/SOAPTunneling/0/{0}/", vid);

 

//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);

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.