Universal Messaging 9.10 | Universal Messaging Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Peer to Peer | Peer to Peer Event-based Clients
 
Peer to Peer Event-based Clients
Universal Messaging Peer to Peer Event-based Services communicate via events which are published by a Client, and received and responded to by an Event-based Server Service.
The Universal Messaging P2P API is simple to use. There are only a very small number of objects and calls that need to be made in order for you to construct a P2P Service Client, connect to a Realm, and find or list available Services.
Creating an Event-based Service Client
The nServiceFactory object establishes a connection with the Universal Messaging Realm, and is the factory object from which we can find our Service, or obtain a list of available Services:

String[] RNAME={"nsp://127.0.0.1:9000"};
nSessionAttributes nsa = new nSessionAttributes(RNAME);
nServiceFactory factory = new nServiceFactory( nsa );

nServiceInfo info = factory.findService("example");
nEventService serv = (nEventService)factory.connectToService( info );
Once the Client has connected to an instance of a Server Service, the developer's custom business logic can then be applied.
Sending Events to Server Services
Once you have connected to the Service, and you have an instance of the Service, you can then begin publishing your Universal Messaging events to the Service, by using the following command:

serv.write(new nConsumeEvent("TAG", (new UTF8Encoding()).GetBytes("Hello World")));
To receive responses from the Server Service, the client Service can receive events either synchronously or asynchronously via a callback interface.
Synchronously Receiving Events from the Server Service
Clients can synchronously read incoming events. The following code will return an event once one is received from the Server Service:

nConsumeEvent event = serv.read();
Asynchronously Receiving Events from the Server Service
A Client may alternatively asynchronously receive events from the Event-based Server Service by implementing the nEventServiceListener interface and its receivedEvent method:

public void receivedEvent(nConsumeEvent evt) {
Console.WriteLine("Consumed event " + event.getEventID());
}
You will also need to call registerListener(your_listener_class) on the nEventService object.

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.