GithubHelp home page GithubHelp logo

wirecloud-pubsub's Introduction

Requirements

Installation

You can get wirecloud-pubsub from PyPI with...

# pip install wirecloud-pubsub

Since wirecloud_pubsub uses django.contrib.static functionalities, you should add it to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
    ...
    'wirecloud_pubsub',
    ...
)

As last step, add a DEFAULT_SILBOPS_BROKER setting with the URL of the broker to use:

DEFAULT_SILBOPS_BROKER = 'http://pubsub.server.com:8080/silbops/CometAPI'

Don't forget to run the collectstatic and compress commands on your Wirecloud installation:

$ ./manage.py collectstatic
$ ./manage.py compress

Usage

Once wirecloud-pubsub is installed and activated, widgets and operators can take advantage the PubSub functionallities through the MashupPlatform.SilboPS object. Currently, the MashupPlatform.SilboPS object only exports the PubEndPoint, SubEndPoint and Filter classes defined by the original javascript bindings provided by SilboPS. Full documentation of SilboPS is available at https://github.com/conwetlab/silbops.

Examples

Publishing

var endpoint;

function publish() {
    var notification = new MashupPlatform.SilboPS.Notification()
        .attribute("value", SilboPS.Type.LONG, Math.floor((Math.random() * 100) + 1))
        .attribute("fqn", SilboPS.Type.STRING, "es.upm.fi.machine1")
        .attribute("eventType", SilboPS.Type.STRING, "monitoring.cpu");
}

function start_publishing() {
    var advertise = new MashupPlatform.SilboPS.Advertise()
        .attribute("value", SilboPS.Type.LONG)
        .attribute("fqn", SilboPS.Type.STRING)
        .attribute("eventType", SilboPS.Type.STRING);

    endpoint.advertise(advertise);
    setInterval(publish, 2000);
}

endpoint = new MashupPlatform.SilboPS.PubEndPoint({
    open: function(endpoint) {
        alert('Endpoint ready');
        start_publishing();
    },
    close: function(endpoint) {
        alert('Endpoint closed');
    }
});

Subscribing

var endpoint, filter;

function create_subscription() {
    var cxtFunc = new SilboPS.ContextFunction();
    var subscription = new SilboPS.Subscription()
        .constrain("fqn", SilboPS.Type.STRING).startsWith("es.upm.fi.")
        .constrain("eventType", SilboPS.Type.STRING).eq("es.upm.fi.")
        .subscription();

        endpoint.subscribe(subscription, cxtFunc);
};

endpoint = new MashupPlatform.SilboPS.SubEndPoint({
    open: function (endpoint) {
        endpoint.subscribe(filter);
        alert('Endpoint ready');
    },
    close: function (endpoint) {
        alert('Endpoint closed');
    },
    notify: function (endpoint, data) {
        var notification = data.notification;
        alert(notification.value);
    }
});

wirecloud-pubsub's People

Contributors

aarranz avatar svavassori avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.