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

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

The GOAL for this setup is:

CODE server

/**
 *   @file         example/go/MyRouter.go
 *   @brief        MyRouter.go - 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>
 */


package main

import (
  . "gomsgque/mkkernel"
  . "gomsgque/mqmsgque"
    "os"
    "fmt"
)

// ************************************************************

const id1 = 11
const id2 = 12

type Basic struct { MqContextC }

func (this *Basic) CreateWorker(master_id int32, factory string) {
  this.SlaveWorkerVA(master_id, factory, "--prefix",  "cl"+factory+"-"+fmt.Sprint(master_id), "@",
                                         "--prefix",  "sv"+factory+"-"+fmt.Sprint(master_id))
}

type HLWO Basic
  func (this *HLWO) Call() {
    this.Send("R", "C", this.ConfigGetName())
  }

type FOID Basic
  func (this *FOID) Call() {
    this.Send("R", "C", this.ClassOriginalIdentGet() + "-" + fmt.Sprint(this.LinkGetCtxId()))
  }

type PATH Basic
  func (this *PATH) Call() {
    this.Send("R", "C", this.RouteGetPath())
  }

type TREE Basic
  func (this *TREE) Call() {
    this.Send("R", "L", this.RouteGetTree())
  }

type HLWS Basic
  func (this *HLWS) Call(ctx *MqContextC) {
    (*Basic)(this).Setup()
    ctx.SendRETURN()
  }

func (this *Basic) Setup() {
  this.ServiceCreate("HLWO", (*HLWO)(this))
  this.ServiceCreate("FOID", (*FOID)(this))
  this.ServiceCreate("PATH", (*PATH)(this))
  this.ServiceCreate("TREE", (*TREE)(this))
  this.ServiceCreate("HLWS", (*HLWS)(this))
}

// ************************************************************

type WO1 struct { Basic }

func WO1_Factory (tmpl MqContextCI) MqFactoryI {
  srv := new(WO1)
  srv.Init(tmpl, srv)
  return srv
}

func (this *WO1) ServerSetup() {
  if (this.LinkIsParent()) {
    this.CreateWorker (id1, "WO2");
    this.CreateWorker (id2, "WO2");
  }
  this.Setup();
}

// ************************************************************

type WO2 struct { Basic }

func WO2_Factory (tmpl MqContextCI) MqFactoryI {
  srv := new(WO2)
  srv.Init(tmpl, srv)
  return srv
}

func (this *WO2) ServerSetup() {
  if (this.LinkIsParent()) {
    this.CreateWorker (id1, "WO3");
    this.CreateWorker (id2, "WO3");
  }
  this.Setup();
}

// ************************************************************

type WO3 struct { Basic }

func WO3_Factory (tmpl MqContextCI) MqFactoryI {
  srv := new(WO3)
  srv.Init(tmpl, srv)
  return srv
}

type LINK WO3
  func (this *LINK) Call() {
    this.Send("R", "C", "FINL-" + this.ConfigGetName())
  }

func (this *WO3) ServerSetup() {
  this.ServiceCreate("FINL", (*LINK)(this))
  this.Setup()
}

// main *********************************************************

/// [factory_example]
func main() {

  // create a buffer-list from the GO application arguments
  largv := MkBufferListCreateVC(os.Args)

  // add factories
  MqFactoryAdd(WO1_Factory, "WO1").Default()
  MqFactoryAdd(WO2_Factory, "WO2")
  MqFactoryAdd(WO3_Factory, "WO3")

  // select factory using the !first! application argument
  // and create a new server
  srv := MqFactoryGetCalledL(largv).New()

  // catch error start
  defer func() {
    if x := recover(); x != nil {
      // set the libmqmsgque error from the GO error
      srv.ErrorCatch_1(x)
    }
    // exit aplication and cleanup the environment
    srv.Exit_0()
  }()

  // configure and start the server
  srv.LinkCreate(largv)

  // start event-loop and wait forever
  srv.ProcessEvent_1(MQ_WAIT_FOREVER)
}
/// [factory_example]