Message Oriented Middlewares Fabienne Boyer, fabienne.boyer@inria.fr Introduction RPC Synchronous communications Explicit identification of the receiver(s) 1-1 connexion -> Strongly coupled components MOM Asybchronous communications Anonymous 1-N -> Weakly coupled components Fabienne Boyer, Distributed Programming 2 Application examples Monitoring application example Event-based applications Network monitoring Workflow Administration ( Integration EAI (Enterprise Application Heterogeneous information systems Interrogation A application monitors server nodes and application states Update a centralized database Complex configuration Dynamic (adding / removing server nodes as well as applications) Human administrators inspect the collected data Fabienne Boyer, Basics of Distributed Programming 3 Fabienne Boyer, Basics of Distributed Programming 4 1
Application example Solution MOM MOM principles Managed elements send messages When their state evolves Alerts, statistics Two main communication patterns Message Queuing Publish/Subscribe One or more daemons receive messages Keep current system state in a database Raise alerts Fabienne Boyer, Basics of Distributed Programming 5 Message Queuing Message Queuing Communication via une file de message Asynchronisme Client Serveur Communication asynchrone send recv Indépendance de l émetteur et du récepteur (pas forcément actif) Communication 1-1 et non anonyme Un seul récepteur identifié Serveur 8 2
Publish-Subscribe Publish-Subscrive Anonymous The sender emits a message (, fsubject-based:failure,load ) Subject-based: (* content-based:*kernighan ) Content-based A receiver subscribe to a subject or content Communication 1-N Several receivers for a given message producteur publish "... " " consommateur subscribe recv MOM Properties MOM Design: centralized server Availability Unavailability time less than few minutes per year Robustness Message delivrance guarantee Ordering Atomicity (for a sequence of sending/receiving) Scalability Tolerates load increases Security Confidentiality Integrity Persistence Stopping the MOM è restart without state loss Simplicity Low availability Low scalability Serveur 3
MOM Design: distributed servers MOM Design: message bus Distributed servers Static or dynamic organization Message routing Availability A server can be replaced by another serveur Not transparent Scalability Balance the load serveur Strategies (by s / by topic) serveur serveur Processus_a Interface Bus Services du bus logiciel Système d exploitation Machine A protocoles du bus logiciel Processus_b Interface Bus Services du bus logiciel Système d exploitation Machine B MOM Example: AAA The AAA Platform AAA Platform A programming model Distributed agents communicating through events A runtime Based on a message bus Execution model Reactive objects React to a notification Notifications sent through the message bus s State Reactions rules SendTo Message bus React 4
AAA Properties s Persistents (state saved on disk)) Atomic reactions (consistent state) A C AAA Programming Model s Java objects that inherit from Identified by an agentid public class HelloWorld extends { Communications Asynchrones (disconnected mode) Robust (sent/received as soon as the network allows it ) Causally ordered B public HelloWorld(short to, String name) { super(to, name); ( not public void react(id from, Notification throws Exception { AAA Programming Model (2) AAA Programming Model (3) Notifications Serializable objects that inherits from Notification Used at application level and at runtime level Notification sending ( file To an agent (message queue / ( pub/sub ) To a Role or RoleMultiple public class HelloWorldNot extends Notification { sendto(id ag, Notification n) ou ( n sendto(role role, Notification public String msg = "Hello world"; ag: receiver identification public HelloWorldNot(String msg) { this.msg = msg; role: topic identification n: the notification 5
identification Programming model (4) ( from ) Identification of the agent server that created the agent ( to ) Identification of the agent server that hosts the agent Event-reaction model Event = notification sent by an agent to another one Réaction method to process when receiving a notification ( from-stamp ) Local stamp Creation engine Localisation engine Stamp attribute1 :... attribute2 :... 16 bits 16 bits 32 bits (...) event1 (...) event2 (...) dest1 (...) dest2 example creation and deployment public class HelloWorld extends { public Id dest; public HelloWorld(short to, String name) { super(to, name); public void react(id from, Notification not)throws Exception { if (n instanceof HelloWorldNot) { System.out.println(((HelloWorldNot)n).msg); // send a new notification sendto(dest, new HelloWorldNotReceived()); else // core notification processing super.react(from,not); Fabienne Boyer, Distributed Programming 1. Local instanciation 2. Distributed deployment short asid;.. // Create agent ag // ag should be deployed on Server asid Ag ag = new Ag(asId); // We can assign local attributes ag.x = 32; // Effective deployment ag.deploy(),.. Fabienne Boyer, Distributed Programming 24 6
Static distributed configuration server creation (by command) <?xml version="1.0"?> <!DOCTYPE config SYSTEM "a3config.dtd"> <config name="test_conf1"> <host hostname="localhost"> <server id="0" name="s0" port="27300"> </server> <server id="1" name="s1" port="27301"> </server> </host> </config> > java fr.dyade.aaa.agent.server num rac // num = numéro du serveur // rac = racine de persistence // exemple : java fr.dyade.aaa.agentserver Client Interface I 1 s1 Server Fabienne Boyer, Distributed Programming 25 Fabienne Boyer, Distributed Programming 26 server creation (by program) AAA Design public class Launch { public static void main (String args[]) { try { Server.init(args); 0 // Create agent ag to be deployed on Server Ag ag = new Ag((short)0); ag.deploy(), // Send a notification Channel.sendTo(ag.getId(), new not()); server transport Notification Persistent queues Processing reactions.. // Become an Server Server.start(); Fabienne Boyer, Distributed Programming 27 Fabienne Boyer, Distributed Programming 28 7
AAA Design server design Server JVM Includes a bus and an agent factory Allocates identifier and manages the agent persistence Local Bus Manages local communications Ensures atomicity and robustness Interconnected with other bus Composed of a Channel and an Engine Channel Localisation and transport of notifications Engine Execution server Fabienne Boyer, Basics of Distributed Programming 29 server design server internals Mono-threaded server Any reaction processed as a transaction SendTo Channel qout React Engine qin msg = qin.get(); agent =.load(msg.to); agent.react(msg.from, msg.not); () transaction.begin qin.pop(); channel.dispatch();.save(); () transaction.commit Network 8