Tianming GUO
RICM5
14/11/2014
Publisher
Mediator
Subscriber
Envoyer les changement
Registrer l'abonnement
Recevoir l'événement
Filtrer l'événement
Routing
Envoyer les abonnement avec "Topic"
Publisher_1
Publisher_2
Mediator
Subscriber_1
Subscriber_2
Subscriber_3
Subscribe(X)
Subscribe(X)
Subscribe(Y)
Publish(X)
Publish(Y)
Notify
Notify
Notify
Deux rôles:
Deux attributs:
"org/osgi/framework/BundleEvent/ERROR"
Event reportGeneratedEvent = new Event("com/acme/reportgenerator/GENERATED", properties);
public void reportGenerated(Report report, BundleContext context)
{
ServiceReference ref = context.getServiceReference(EventAdmin.class.getName());
if (ref != null)
{
EventAdmin eventAdmin = (EventAdmin) context.getService(ref);
Dictionary properties = new Hashtable();
properties.put("title", report.getTitle());
properties.put("path" , report.getAbsolutePath());
properties.put("time", System.currentTimeMillis());
Event reportGeneratedEvent = new Event("com/acme/reportgenerator/GENERATED", properties);
eventAdmin.sendEvent(reportGeneratedEvent);
}
}
Créer un Serveur(synchrone) avec Topic: "com/acme/reportgenerator/GENERATED"
String[] topics = new String[] {
"com/acme/reportgenerator/GENERATED"
};
Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, topics);
props.put(EventConstants.EVENT_FILTER, "(title=samplereport)");
bundleContext.registerService(EventHandler.class.getName(), new ReportEventHandler() , props);
public class ReportEventHandler implements EventHandler
{
public void handleEvent(Event event)
{
String reportTitle = (String) event.getProperty("title");
String reportPath = (String) event.getProperty("path");
sendReportByEmail(reportTitle, reportPath);
}
Créer un EventHandler
Registrer un EventHandler(avec filtre)
channel.basic_publish(exchange='',
routing_key='hello',
body=message)
Par nom:
Par route:
channel.basic_publish(exchange='logs',
routing_key='',
body=message)
Etape 1 : Exchange
1.1 Choisir un type d'échange : direct, topic, headers, fanout
channel.exchange_declare(exchange='logs',
type='fanout')
1.2 Choisir la bonne queue
Etape 2 : Binding
channel.queue_bind(exchange='logs',
queue=result.method.queue)
Etape 3 : Commencer à envoyer
Publisher - Hub - Subscriber
MQTT : Publisher + Server + Subscriber
UPNP : General Event Notification Architecture
ROS : Robot Operating System -- Envoies des événements
RTPS : Real-Time Publish-Subscribe, basé sur UDP
60 + languages et plate-forme de développement dans ses SDKs
Instancier le PubNub
<!-- Include the PubNub Library -->
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<!-- Instantiate PubNub -->
<script type="text/javascript">
var PUBNUB_demo = PUBNUB.init({
publish_key: 'demo',
subscribe_key: 'demo'
});
</script>
//Subscribe to the demo_tutorial channel
PUBNUB_demo.subscribe({
channel: 'demo_tutorial',
message: function(m){console.log(m)}
});
Subscribe
// Publish a simple message to the demo_tutorial channel
PUBNUB_demo.publish({
channel: 'demo_tutorial',
message: {"text":"Hey!"}
});
Publish