rbmqmsgque 9.0
Loading...
Searching...
No Matches
Example: MyRouter

Documentation of the MyRouter tool used for route2.test.

INTRODUCTION

The MyRouter tool is used to test the routing-feature of rbmqmsgque.

To perform the test multiple classes are created and connected using the rbmqmsgque protocol.
The following class-hierarchie is used:

       Base
   |----|----|
  WO1  WO2  WO3       

The routing-test is perfomed by connecting multiple context.

  • The client connect to the WO1-context.
  • On WO1-ServerSetup the WO1-context create two WO2-context using the CreateWorker methode from Base.
  • On WO2-ServerSetup the W02-context create two WO3-context using the CreateWorker methode from Base.
                           |-> WO3#1
                |-> WO2#1 -|-> WO3#2
 client -> WO1 -|
                |-> W02#2 -|-> WO3#1
                           |-> WO3#2

All context created, 1x client and 7x server, are connected using the rbmqmsgque protocoll and build together a tree-like structure.

The GOAL for this setup is:

CODE server

#+
#:   @file         example/ruby/MyRouter.rb
#:   @brief        MyRouter.rb - 02 May 2023 - aotto1968
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permissions to copy,
#:                 please contact AUTHOR for additional information
#:   @version      d2cd8f6ec2179f5e5583ae98faed11359996631d
#:   @date         Tue May 2 21:28:46 2023 +0200
#:   @author       aotto1968 <aotto1968@t-online.de>
#:

require "rbmqmsgque"
include PyMsgque::MkKernel
include PyMsgque::MqMsgque

class Basic < MqContextC
  @@id1 = 11
  @@id2 = 12
  def initialize()
    super()
  end
  def CreateWorker(master_id, factory)
    SlaveWorker( master_id, factory,  "--prefix", "cl#{factory}-#{master_id}", "@",   \
                                      "--prefix", "sv#{factory}-#{master_id}"         \
    )
  end
  def HLWO
    Send("R", "C", ConfigGetName())
  end
  def FOID
    Send("R", "C", "#{ClassOriginalIdentGet()}-#{LinkGetCtxId()}")
  end
  def PATH
    Send("R", "C", RouteGetPath())
  end
  def TREE                            ; # private context, only callable by "self"
    Send("R", "L", RouteGetTree())    ; # answer the service-call using the "self" context
  end
  def HLWS(ctx)                       ; # public context, callable from every "ctx"
    Setup()                           ; # calling "setup" using the "self" context
    ctx.Send("R")                     ; # answer the service-call using the "ctx" context
  end
  def Setup
    ServiceCreate("HLWO",method(:HLWO))
    ServiceCreate("FOID",method(:FOID))
    ServiceCreate("PATH",method(:PATH))
    ServiceCreate("TREE",method(:TREE))   ; # method is linked to "self"
    ServiceCreate("HLWS",method(:HLWS))   ; # method is linked to "self"
  end
end

class WO1 < Basic
  def initialize()
    super()
    ConfigSetServerSetup(method(:ServerSetup))
  end
  def ServerSetup
    if LinkIsParent()
      CreateWorker(@@id1, "WO2")
      CreateWorker(@@id2, "WO2")
    end
    Setup()
  end
end

class WO2 < Basic
  def initialize()
    super()
    ConfigSetServerSetup(method(:ServerSetup))
  end
  def ServerSetup
    if LinkIsParent()
      CreateWorker(@@id1, "WO3")
      CreateWorker(@@id2, "WO3")
    end
    Setup()
  end
end

class WO3 < Basic
  def initialize()
    super()
    ConfigSetServerSetup(method(:ServerSetup))
  end
  def FINL
    Send("R", "C", "FINL-" + ConfigGetName())
  end
  def ServerSetup
    Setup()
    ServiceCreate("FINL",method(:FINL))
  end
end

# ------------------------------------------------------
# Main

# create buffer-list of the application arguments
largv = MkBufferListC.CreateLA(ARGV)

# create the factories…
MqFactoryC.Add(WO1).Default()
MqFactoryC.Add(WO2)
MqFactoryC.Add(WO3)

# select factory using the !first! application argument
# and create a new server
srv = MqFactoryC.GetCalledL(largv).New()

begin
  # configure and start the server
  srv.LinkCreate(largv)

  # start event-loop and wait forever
  srv.ProcessEvent(MqWaitOnEventE::FOREVER)

rescue Exception => ex
  srv.ErrorCatch(ex)

ensure
  srv.Exit()

end