Coder Social home page Coder Social logo

eventifyio / eventify Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 4.0 3.12 MB

Lightweight Module for Asynchronous Event Driven Systems

License: MIT License

Python 98.76% Shell 1.08% Dockerfile 0.16%
python event-driven websocket crossbar producer-consumer eventify

eventify's Introduction

Build Status Coverage Status Documentation Status

Eventify

A lightweight python module for building event driven distributed systems.

Installation

pip install eventify

Problem

Developers need a easy and fast way to implement business logic in a modern asynchronous way. Developers should not have to worry about service communication.

Contributing

TBD

Architecture

ArchDiagram

Tutorial

Below is everything you need to get started using the eventify project.

Minimum Viable Service

Create an Event handler function to receive events. To publish events, use session.emit_event() within the Event handler function. To start your service (and begin listening for events), pass the Event handler function as a callback to run a Service.

#!/usr/bin/env python
"""
Minimal viable microservice
"""
import asyncio
import logging
import sys

from eventify.base_handler import BaseHandler
from eventify.event import Event
from eventify.service import Service


class GoogleCollector:
    """
    Google Specific Collector
    """

    async def collect_vm_data(self):
        print('...collecting data from gce api...')
        await asyncio.sleep(1)

class Collector(BaseHandler, GoogleCollector):
    """
    Generic collector
    """

    async def init(self):
        """
        Service initialization
        """
        print('...service initialized...')


def run():
    """
    Run an eventify service
    """
    Service(
        config_file='config.json',
        handlers=[Collector]
    ).start()

if __name__ == '__main__':
    run()

Minimum Configuration - config.json

Each application (service, microservice, etc.) can publish to 0 or 1 topic and subscribe to 0 or more topics. Thus each application requires its own configuration file which defines its publications & subscriptions. Each configuration file also specifies the location of the transport host.

{
    "_comment": "service configuration",
    "name": "example",
    "image": "example/service",
    "driver": "crossbar",
    "transport_host": "ws://events-server:8080/ws",
    "pub_options": {
        "acknowledge": true,
        "retain": true
    },
    "publish_topic": {
        "topic": "example",
        "timeout": 20,
        "reply_in": 0
    },
    "subscribed_topics": [
        "ui-events"
    ],
    "replay_events": true,
    "replay_type": "event_store"
}

Event History Support

To add event history support add the @event_tracker decorator to any event handler your define.

Environment variables

  • EVENT_DB_HOST

Hostname of database server

  • EVENT_DB_USER

Username for database server

  • EVENT_DB_PASS

Password for username

  • EVENT_DB_TYPE

Database driver type - defaults to postgres

  • EVENT_DB_POOL_SIZE

Database connection pool size - defaults to 5

  • EVENT_TRACKING_HOST

For use with replay functionality - host of in memory cache

Supported Drivers

  • Crossbar
  • Kafka

Crossbar

Quickest way to get started with crossbar is to use docker; both redis and postgresql are required for a minimal working service.

Running Crossbar

docker run -d -p 8080:8080 -it crossbario/crossbar:latest

Running Kafka

  • TBD

Running Redis

docker run -d -p 6379:6379 -t redis:latest

Running Postgresql

docker run --name postgres-container -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres

Note: This does not have a volume or persistant storage so in a production environment you would want to configure a volume

See More

http://crossbar.io

Pypi

https://pypi.python.org/pypi/eventify

Read The Docs

http://eventify.readthedocs.io/en/latest/

eventify's People

Contributors

dependabot[bot] avatar malkush avatar mmalkush avatar morissette avatar pyup-bot avatar yuriysemen-edvantis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eventify's Issues

Eventify 0.4.6 - error in `eventify.drivers.crossbar.Component.onConnect`

Method

eventify.drivers.crossbar.Component.onConnect

should call

eventify.drivers.base.BaseComponent.onConnect

but instead it calls

autobahn.wamp.protocol.ApplicationSession.onConnect

on line 40:

    async def onConnect(self):
        """
        Inherited from BaseComponent
        """
        super(BaseComponent, self).onConnect()  # <-- Here
        self.log.info("connected")
        self.join(self.config.realm)

Which causes an exception from method

eventify.drivers.crossbar.Component.onJoin

because self.handlers property doesn't exists in line 149
(it is set ineventify.drivers.base.BaseComponent.onConnect):

    async def onJoin(self, details):
        self.log.debug("joined websocket realm: %s", details)

        # set session_id for reconnect
        self.session_id = details.session
        self.realm_id = details.realm

        for handler in self.handlers:  # <-- Here
            # initialize handler
            handler_instance = handler()
            handler_instance.set_session(self)
            ...

Python 3.6.2, linux (Debian family).

add replay support

subscribing services should be able to replay events from a given event_id or timeframe

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.