phpmqmsgque 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 phpmqmsgque.

To perform the test multiple classes are created and connected using the phpmqmsgque 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 phpmqmsgque protocoll and build together a tree-like structure.

The GOAL for this setup is:

CODE server

<?php
#+
#:   @file         example/php/MyRouter.php
#:   @brief        MyRouter.php - 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>
#:

use PhpMsgque\MqMsgque as mq;
use PhpMsgque\MkKernel as mk;

abstract class Basic extends mq\MqContextC implements mq\iServerSetup {
  const id1 = 11;
  const id2 = 12;

  protected function CreateWorker($master_id, $factory) {
    $this->SlaveWorker( $master_id, $factory,
              '--prefix', 'cl' . $factory . '-' . $master_id, '@',
              '--prefix', 'sv' . $factory . '-' . $master_id
    );
  }

  public function HLWO() {
    $this->Send("R", "C", $this->ConfigGetName());
  }

  public function FOID() {
    $this->Send("R", "C", $this->ClassOriginalIdentGet() . '-' . $this->LinkGetCtxId());
  }

  public function PATH() {
    $this->Send("R", "C", $this->RouteGetPath());
  }

  public function TREE() {
    $this->Send("R", "L", $this->RouteGetTree());
  }

  public static function HLWS($ctx) {
    $ctx->SlaveGetMaster()->Setup();
    $ctx->Send("R");
  }

  protected function Setup() {
    $this->ServiceCreate('HLWO', 'HLWO');
    $this->ServiceCreate('FOID', 'FOID');
    $this->ServiceCreate('PATH', 'PATH');
    $this->ServiceCreate('TREE', 'TREE');
    $this->ServiceCreate('HLWS', array('Basic', 'HLWS'));
  }
}

class WO1 extends Basic {
  public function ServerSetup() {
    if ($this->LinkIsParent()) {
      $this->CreateWorker(self::id1, "WO2");
      $this->CreateWorker(self::id2, "WO2");
    }
    $this->Setup();
  }
}

class WO2 extends Basic {
  public function ServerSetup() {
    if ($this->LinkIsParent()) {
      $this->CreateWorker(self::id1, "WO3");
      $this->CreateWorker(self::id2, "WO3");
    }
    $this->Setup();
  }
}

class WO3 extends Basic {
  public function FINL() {
    $this->Send("R", "C", "FINL-" . $this->ConfigGetName());
  }
  public function ServerSetup() {
    $this->Setup();
    $this->ServiceCreate('FINL', 'FINL');
  }
}

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

# create buffer-list of the application arguments
$largv = mk\MkBufferListC::CreateLA($argv);

# create the factories…
mq\MqFactoryC::Add('WO1')->Default();
mq\MqFactoryC::Add('WO2');
mq\MqFactoryC::Add('WO3');

# select factory using the !first! application argument
# and create a new server
$srv = mq\MqFactoryC::GetCalledL($largv)->New();

try {
  # configure and start the server
  $srv->LinkCreate($largv);

  # start event-loop and wait forever
  $srv->ProcessEvent(mq\MqWaitOnEventE::FOREVER);

} catch (Throwable $ex) {
  $srv->ErrorCatch($ex);

} finally {
  $srv->Exit();
}

?>