Beruflich Dokumente
Kultur Dokumente
Introduction
Part I - Basic
Part II - Internal.
Introduction
Sources
I read the Juval Lowy Article on msdn magazine but the article is based on topic
based pub/sub scheme .But for many cases a simple pub/sub scheme is needed
without topic scheme .So i made many changes to the code and finally made a
simplified version,i hope that this simplified implementation with multiple protocol
support will be helpful to many men like me in their project.The code used in this
article is based on the juva's lovy article, but some parts are not changed.
Part I - Basic
What is Event Notification Server?
Event Notification Server is an “Event Notification” system. It connects programs
that provide information changes over time (publishers) with programs that want to
receive notifications of those changes (subscribers). It is the middle ware that deals
with publishers and subscribers.
There are essentially two main groups applications that communicate through
networks or the Internet - client server and the and peer-to-peer. Event Notification
Server employ client server architectures for better performance.
Here the Event Notification Server expose different protocols based connectivity. A
client
based on his requirement will choose protocol to connect.
If a client is in the same machine with Event Notification Server (ENS) then it will
connect with ENS thru Named Pipe protocol Because Named Pipe protocol is the
fastest for same machine boundary.
If a client is in the same Local Area Network (LAN) with ENS it will connect with ENS
thru TCP protocol Because TCP is a connection oriented reliable protocol.
If a client is in the same Virtual Private Network (VPN) with ENS then it will connect
with ENS thru TCP protocol Because TCP is a connection oriented reliable protocol.
If a client is in the Internet with ENS then it will connect with ENS thru HTTP protocol
Because HTTP is a firewall friendly protocol.It is unidirectional by default but using
wsdualhttp binding i get bidirectional behavior.
Here each client will register himself to ENS then when an event comes to ENS then
ENS will send it to clients that are registered.
For Example we have 10 clients and all 10 clients would register to the ENS to
receive notifications (client programs are individual programs) and then whenever
the event occurs from the publisher, the ENS notifies all those clients.
In the VS2008 just press F5 to launch total system and then it will be ready to go.
2. For sending auto event set the interval then click the button
“Fire Auto Event”.
How to receive event:
Part II - Internal.
Data Structure:
Algorithm:
Subscribers that want to subscribe to events will register with the subscription
service.
o Then Publisher will send the event to each subscriber of the list.
[DataMember]
public string SeqNo { get { return _SeqNo; } set { _SeqNo = value; } }
[DataMember]
public string Description { get { return _Description; } set { _Description
= value; } }
}
Event Publishing
The publishing service exposes the events contract in an endpoint, you need to mark
the events contract as a service contract.
[ServiceContract]
interface IEvent
{
[OperationContract(IsOneWay = true)]
void OnEvent(AlertData e);
}
To provide your own publishing service, derive from IEvent and use method to
deliver the event to all subscribers.
/// This method is called from the publisher client to send the event.
public void OnEvent(AlertData e)
{
}
}
}
}
Managing Registration(subscriptions):
[OperationContract]
void UnRegister();
[OperationContract]
string GetDateTime();
}
The application needs to expose its own subscription service in the form of an
endpoint that supports its specific interface of IRegistration. To do so, the application
needs to provide a service class that derives from IRegistration specify the callback
contract as a type parameter,.
/// This is the class for Subscription Service that is deployed to listen.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
class Subscription : IRegistration
{
/// This the data structue that is used for pub/sub scheme.
/// Here list is used to hold the subscribers.
/// This is constructor of the class.It is used here to create the instance
/// of the pub/sub data structure
static Subscription()
{
m_ClientList = new List<IEvent>();
}
/// This method return the complete subscriber list to publisher service.
}
stores subscribers in a generic static list.
The Register ( ) method extracts the callback reference from the operation call
context. Then retrieves the list of subscribers for the event from the store. If the list
does not contain the subscriber, it adds it in. UnRegister() operates in a similar
manner.
Hosting
For hosting you have to expose Publishing service multiple times for multiple
protocols.
For hosting you have to expose Subscription service multiple times for multiple
protocols
subscriptionManagerHost.AddServiceEndpoint(typeof(IRegistratio
n),
wsDualBinding,
"http://localhost:8003/SubscriptionServ
ie/");
subscriptionManagerHost.AddServiceEndpoint(typeof(IRegistration
),
tcpBinding,
"net.tcp://localhost:8002/SubscriptionServi
e");
subscriptionManagerHost.AddServiceEndpoint(typeof(IRegistration
),
namedPipeBinding,
"net.pipe://localhost/MyPipe2");
//This line is used to open sub service to listen.
subscriptionManagerHost.Open();
</configuration>
SecurityMode.None is used here so that it can communicate over cross domain and
over vpn.
Here the code implement most simple scenario of pub/sub scheme without topic
based which is helpful in many scenarios.
and then i will show how windows and certificate authentication can be implemented
using this implementation.
Referance