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

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

The GOAL for this setup is:

CODE server

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

Option Infer On

Imports System
Imports System.Collections.Generic
Imports csmsgque.mkkernel
Imports csmsgque.mqmsgque

Public Module example

' F1 ********************************************************
  Public MustInherit Class Basis
    Inherits MqContextC
    Implements IServerSetup

    Protected Dim Shared ReadOnly id1 As Integer = 11
    Protected Dim Shared ReadOnly id2 As Integer = 12

    Public Sub New(Optional ByVal tmpl As MqContextC = Nothing)
      MyBase.New(tmpl)
    End Sub

    Protected Sub CreateWorker(master_id As Integer, factory As String)
      SlaveWorker(master_id, factory,
        "--prefix", "cl" + factory + "-" + CStr(master_id),
          "@",
            "--prefix", "sv" + factory + "-" + CStr(master_id)
      )
    End Sub

    Protected Sub HLWO()
      Send("R", "C", ConfigGetName())
    End Sub

    Protected Sub FOID()
      Send("R", "C", ClassOriginalIdentGet() + "-" + CStr(LinkGetCtxId()))
    End Sub

    Protected Sub PATH()
      Send("R", "C", RouteGetPath())
    End Sub

    Protected Sub TREE()
      Send("R", "L", RouteGetTree())
    End Sub

    Protected Shared Sub HLWS(ByVal ctx As MqContextC)
      Dim master As Basis = ctx.SlaveGetMaster()
      master.Setup()
      ctx.SendRETURN()
    End Sub

    Protected Sub Setup ()
      ServiceCreate("HLWO", AddressOf HLWO)
      ServiceCreate("FOID", AddressOf FOID)
      ServiceCreate("PATH", AddressOf PATH)
      ServiceCreate("TREE", AddressOf TREE)
      ServiceCreate("HLWS", AddressOf HLWS)
    End Sub
    
    Protected MustOverride Sub ServerSetup () Implements IServerSetup.ServerSetup
  End Class

' ********************************************************

  Private NotInheritable Class WO1
    Inherits Basis

    Public Sub New(Optional ByVal tmpl As MqContextC = Nothing)
      MyBase.New(tmpl)
    End Sub

    Protected Overrides Sub ServerSetup()
      If LinkIsParent()
        CreateWorker (id1, "WO2")
        CreateWorker (id2, "WO2")
      End If
      Setup()
    End Sub
  End Class

' ********************************************************

  Private NotInheritable Class WO2
    Inherits Basis

    Public Sub New(Optional ByVal tmpl As MqContextC = Nothing)
      MyBase.New(tmpl)
    End Sub

    Protected Overrides Sub ServerSetup()
     If LinkIsParent()
        CreateWorker (id1, "WO3")
        CreateWorker (id2, "WO3")
      End If
      Setup()
    End Sub
  End Class

' ********************************************************

  Private NotInheritable Class WO3
    Inherits Basis

    Public Sub New(Optional ByVal tmpl As MqContextC = Nothing)
      MyBase.New(tmpl)
    End Sub

    Private Sub FINL()
      Send("R", "C", "FINL-" + ConfigGetName())
    End Sub

    Protected Overrides Sub ServerSetup()
      Setup()
      ServiceCreate("FINL", AddressOf FINL)
    End Sub
  End Class

' Main ******************************************************
  Sub Main(ByVal argv() As String)

    ' create buffer-list of the application arguments
    Dim largv As New MkBufferListC(argv)

    ' add factories
    MqFactoryC.Add(GetType(WO1)).Default()
    MqFactoryC.Add(GetType(WO2))
    MqFactoryC.Add(GetType(WO3))

    ' select factory using the !first! application argument
    ' and create a new server
    Dim srv As MqContextC = MqFactoryC.GetCalled(largv).[New]()
    Try
      ' configure and start the server
      srv.LinkCreate(largv)

      ' start event-loop and wait forever
      srv.ProcessEvent(MqWaitOnEventE.FOREVER)
    Catch ex As Exception

      ' set the libmqmsgque error from the csharp error
      srv.ErrorCatch (ex)
    End Try

    ' exit aplication and cleanup the environment
    srv.Exit()
  
  End Sub
End Module