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