Giter Club home page Giter Club logo

nodeset.core's Introduction

Framework

Pub/Sub framework for distributed services, nodeset.core is based on Foolscap RPC and twisted. Each "node" is a separate unix process, and all events delivering are performed by dispatcher, the special unix process (also based on foolscap RPC).

Code

Simple subscriber. Publisher code is in example/simple/pub.py

from nodeset.core import message, node, utils

class SimpleMessage(message.NodeMessage):

    def __init__(self):
      message.NodeMessage.__init__(self)
      message.Attribute('field1')


class SimpleNode(node.Node):

    @utils.catch('some_event')
    def callbackForWhatever(self, msg):
      print "EVENT: %s" % msg.toJson()


from nodeset.core import utils
from core import SimpleNode

def do_subscribe(node, event_name):
  print "Subscribing for %s event" % event_name
  node.subscribe(event_name)

def _err(failure):
  print failure

from twisted.internet import reactor

utils.setDefaultOptions()

node = SimpleNode(name='nodeAbc', port=6555)
node.start().addCallback(do_subscribe, 'some_event').addErrback(_err)
node.startService()

reactor.run()

Features

  • Distributed - nodes and dispatcher(s) could be anywhere in network.
  • Stateless
    • dispatcher is completely stateless (after crash/restart the state of dispatcher will be the same as before).
    • nodes share nothing between each other, and restores all subscriptions after dispatcher reconnect
  • HTTP support - nodeset-web helps to implement HTTP API based on nodeset.core pub/sub framework
  • Monitoring - built in monitoring support [WiP]

nodeset.core components:

  • dispatcher - runs on its own, just listen for incoming foolscap RPC calls, and trace which nodes are available, and its health.
  • node - Each Node can act as publisher, as well as subscribers.
  • node collection - group nodes under one listen port

Install (easy_install based)

python setup.py install (or develop for development)

Examples

There are few examples of NodeSet framework usage:

  • example/simple - pub/sub simple implementation

  • examples/node.py - example of NodeCollection, as well as Node usage. Subscription example

  • examples/mnode_publish.py - example of publishing

To run any of example, first you must run dispatcher:

  • nodeset-dispatcher [options]

Node usage example

  • nodeset-node [options]
  • nodeset-node publisher [options]
  • nodeset-node subscriber [options]

Web node usage example

  • nodeset-web web [options]

Options for call is similar to twistd tool in twisted framework, base code was taken from twisted, just use --help to find out available options.

nodeset.core's People

Contributors

selfsk avatar

Stargazers

Angus H. avatar Tim Hughes avatar Guilherme Manika avatar Thomas Morse avatar Greg Work avatar Sergey Rakov avatar  avatar Andrea Turli avatar Clif Smith avatar Dominic LoBue avatar Benjamin W. Smith avatar Joshua Barratt avatar Artur Martins avatar Phil Cryer avatar C Dorn avatar

Watchers

Sergey Rakov avatar

Forkers

sergeyrakov

nodeset.core's Issues

dispatcher raise "Unknown node" failure

It usually happen after node stopped and re-subscribed then, but I guess dispatcher just didn't have enough time to run _dead_reference cleanup code to remove old reference.

2011-08-25 15:58:04-0700 [INFO] [-] Unhandled error in Deferred:
2011-08-25 15:58:04-0700 [INFO] [-] Unhandled Error
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted/internet/defer.py", line 542, in _runCallbacks
current.result = callback(current.result, _args, *_kw)
File "/Users/sk/workdir/sandbox/nodeset_v1/src/nodeset/core/dispatcher.py", line 166, in _do_publish
n.getNode().callRemote(method, event_name, msg).addErrback(err_back, _args)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted/internet/defer.py", line 308, in addErrback
errbackKeywords=kw)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted/internet/defer.py", line 286, in addCallbacks
self._runCallbacks()
--- ---
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted/internet/defer.py", line 542, in _runCallbacks
current.result = callback(current.result, *args, *_kw)
File "/Users/sk/workdir/sandbox/nodeset_v1/src/nodeset/core/dispatcher.py", line 145, in _dead_reference
self.heartbeat.remove(node)
File "/Users/sk/workdir/sandbox/nodeset_v1/src/nodeset/core/heartbeat.py", line 110, in remove
monitor = node.monitor or self._lookup(node)
File "/Users/sk/workdir/sandbox/nodeset_v1/src/nodeset/core/heartbeat.py", line 73, in _lookup
raise KeyError("Unknown node %s" % node)
exceptions.KeyError: 'Unknown node <RemoteReference at 0x1029b1c50 [pb://bsxrdbdrxlofmjaizc4yu6yxhdwpgsrk@localhost:5444/ftpup-controld]>'

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.