Tianming GUO
RICM5
14/11/2014
1. PUB-SUB Introduction
2. Protocols & API
3. PubSub-as-a-Service Providers
4. Démonstration
- Publisher(Editeur)
- Mediator(Médiateur)
- Subscriber(Abonné)
1. PUB-sub Introduction
RÔLEs
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
1. pub-sub Introduction
caractéristique
- Content-based routing
- TCP /UDP/Multicast UDP /Broadcast (in LAN)/mix
- LAN/WAN
- Realtime / Non
- QoS / Non
- Centralisé/Distribué
- Atomicité
- Médiateur/Direct
- One/many to one/many
1. pub-sub Introduction
2. PROTOCOLS & API
OSGi Event-Admin service -- Apache felix
Deux rôles:
- Event Publisher
- Event Handler (ou Subscriber)
Deux attributs:
- Topic : "org/osgi/framework/FrameworkEvent/STARTED"
"org/osgi/framework/BundleEvent/ERROR"
- Event Subscriber "properties": Décrire l'événement
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);
}
}
2. PROTOCOLS & API
OSGi Event-Admin service -- Apache felix
Créer un Serveur(synchrone) avec Topic: "com/acme/reportgenerator/GENERATED"
2. PROTOCOLS & API
OSGi Event-Admin service -- Apache felix
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)
2. PROTOCOLS & API
AMQP (RabbitMQ)
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
2. PROTOCOLS & API
AMQP (RabbitMQ)
Etape 2 : Binding
channel.queue_bind(exchange='logs',
queue=result.method.queue)
Etape 3 : Commencer à envoyer
2. PROTOCOLS & API
PUBSUBHUBBUB - Google
Publisher - Hub - Subscriber
2. PROTOCOLS & API
Upnp, MQTT, ROS, RTPS
MQTT : Publisher + Server + Subscriber
UPNP : General Event Notification Architecture
- Noms de variable d'état
- Valeurs de variable
ROS : Robot Operating System -- Envoies des événements
RTPS : Real-Time Publish-Subscribe, basé sur UDP
3. PUBSUB-AS-A-SERVICE PROVIDERS
PUBNub
60 + languages et plate-forme de développement dans ses SDKs
3. PUBSUB-AS-A-SERVICE PROVIDERS
PUBNub
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>
PUBNub
3. PUBSUB-AS-A-SERVICE PROVIDERS
//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
4. Démonstration
PUBNub
Publish-Subscribe
By Tianming Guo
Publish-Subscribe
- 859