Giter Club home page Giter Club logo

sbf's Introduction

SBF (Super Blazing Fast) a messaging orientated middleware in C.

SBF gives publish/subscribe and request/reply messaging semantics in addition to core networking libraries and common utils (queues, timers and event handling) to build applications. The library uses async callback idiom to deliver messages/events/timers etc. The core event engine is provided by the open source library libevent.

For messaging a choice of TCP or UDP multicast can be used depending on the use case of the application. UDP multicast is better if there is a one to many publish/subscribe topology.

For publish/subscribe a topic is created and one or many publishers can publish messages on the topic and one or many subscribers can listen for messages on that topic.

For request/reply, a publisher sends a single request on a topic and one or more subscribers can send a reply to that specific request for the specific publisher.

SBF is brokerless and uses a deterministic addressing scheme for topic resolution.

Getting Started

To compile the installation for Linux:

$ git submodule update --init --recursive
$ mkdir build
$ cd build
$ cmake ../
$ make install

Dependencies

All dependencies are managed through git submodules.

API modules

Example Usage

Examples for publish/subscribe, request/reply can be found in examples directory this is the best place to start.

When creating an application, typically you need to create the following base compoonents

  • Log
  • KeyValue for properties
  • MW
  • Transport
  • Queue
  • Thead to dispatch Queue

Once complete, publishers, subscribers, timers and events can be created, the callbacks will be delivered via the dispatching queue

The following shows creating each component

Create Log

// Initialise the logging system
log = sbfLog_create (NULL, "%s", "");
sbfLog_setLevel (log, SBF_LOG_OFF);

Create configuration

// Initialise the middleware by defining some properties like the handler
// (e.g. tcp, udp) and the  connection interface (e.g. eth0).
properties = sbfKeyValue_create ();
sbfKeyValue_put (properties, "transport.default.type", "udp");
sbfKeyValue_put (properties, "transport.default.udp.interface", "eth0");

Create MW

mw = sbfMw_create (log, properties);

Create Transport

tport = sbfTport_create (mw, "default", SBF_MW_ALL_THREADS);

Create Queue and thread to dispatch

// Thread entry point for queue dispatch
static void*
dispatchCb (void* closure)
{
    sbfQueue_dispatch (closure);
    return NULL;
}

// Create a queue, the connection port and a thread to dispatch events
queue = sbfQueue_create (mw, "default");
sbfThread_create (&t, dispatchCb, queue);

Create Subscriber for topic

// message callback function
static void
messageCb (sbfSub sub, sbfBuffer buffer, void* closure)
{
    uint64_t* payload = sbfBuffer_getData (buffer);
    uint64_t  now;
    uint64_t  this = *payload;
    double    interval = 0;

    if(CAP_HI_RES_COUNTER == sbfMw_checkSupported (CAP_HI_RES_COUNTER))
    {
        now = sbfPerfCounter_get ();
        if (now > this)
            interval = sbfPerfCounter_microseconds (now - this);
        gTimeTotal += (uint64_t)interval;
        if (interval < gTimeLow)
            gTimeLow = (uint64_t)interval;
        if (interval > gTimeHigh)
            gTimeHigh = (uint64_t)interval;
    }

    gMessages++;
}

sbfSub_create (tport, queue, "TEST_TOPIC", NULL, messageCb, NULL);

sbf's People

Contributors

neueda-anavarro avatar davidtorellineueda avatar colinpattison avatar richardfaloon avatar philberty avatar jonathanmcshaneneueda avatar dtorelli 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.