Project

rb_banyan

0.0
No release in over 3 years
Low commit activity in last 3 years
This gem contains the base class used to create Banyan compatible components requiring connection to a single Banyan backplane. In addition to the base class, executables for rb_backplane and rb_monitor are installed on the executable path.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0

Runtime

~> 2.0
~> 1.1
 Project Readme

RbBanyan

This is the ruby compatible version of the Python Banyan Framework.

Banyan is a lightweight, reactive framework used to create flexible, non-blocking, event driven, asynchronous applications. It was designed primarily to implement physical computing applications for devices such as the Raspberry Pi and Arduino, but it is not limited to just the physical computing domain, and may be used to create applications in any domain.

Banyan applications are comprised of a set of components, each component being a seperate process. Components communicate with each other by publishing and subscribing to language independent protocol messages. As a result, any component can communicate with any other component, regardless of computer language. Each Banyan component connects to a common Banyan backplane that distributes published messages to all message subscribers. The backplane is provided as a command line executable as part of this package and is invoked with

rb_backplane

The backplane must be started before invoking any Banyan component.

In addiition, there is a command line backplane provided as part of the package to monitor all traffic going across the backplane.

To invoke the monitor, type:

rb_monitor

Installation

$ gem install rb_banyan

banyan_base.rb API

A Simple Echo Server

require 'rb_banyan/banyan_base.rb'

class SimpleEchoServer < BanyanBase

  def initialize
    # set the process name for the console banner
    super(process_name: 'SimpleEchoServer')
    
    # allow time for zmq connections to complete
    sleep(0.3)

    # set the subscriber topic
    set_subscriber_topic('echo')

    # wait for messages to arrive
    begin
      receive_loop
    rescue SystemExit, Interrupt
      clean_up
    end
  end

  # process incoming messages - just resend the payload with
  # a topic of 'reply'
  def incoming_message_processing(_topic, payload)
    publish_payload(payload, 'reply')
  end
end


SimpleEchoServer.new

A Simple Echo Client

require 'rubygems'
require 'rb_banyan/banyan_base.rb'

# This is a simple echo client. It sends out a series of messages and expects an
# echo reply from the server

# To use: 1. Start the backplane.
#         2. Start the server.
#         3. Start this client.

class SimpleEchoClient < BanyanBase

  def initialize

    # set the process name for the console banner
    super(process_name:'SimpleEchoClient')

    # allow time for zmq connections to complete
    sleep(0.3)

    # initialize the number of messages to send and receive
    @number_of_messages = @message_number = 10

    # set the subscriber topic
    set_subscriber_topic('reply')

    # send the first message
    publish_payload({'message_number': @message_number}, 'echo')

    # adjust the message number for the next send
    @message_number -= 1

    # get the reply messages
    # wait for messages to arrive
    begin
      receive_loop
    rescue SystemExit, Interrupt
      clean_up
    end
  end

  # With each incoming message, adjust the message number and 
  # publish the next message until the count is achieved.
  def incoming_message_processing(_topic, payload)
    # if all messages received, we are done.
    if payload['message_number'] == 0
        puts('All messages sent and received')
        clean_up
        exit(0)

    # we have more to send - bump the message number and send the message out
    else
      @message_number -= 1
      publish_payload({'message_number': @message_number}, 'echo')
    end
  end
end

SimpleEchoClient.new