gomqmsgque 9.0
Loading...
Searching...
No Matches
Example: MyTransaction

Documentation of the MyTransaction tool used for example.test.

INTRODUCTION

The MyTransaction tool is used to test the longterm-transaction-feature of gomqmsgque.

To test this feature the client connect to the server and send two service-calls:

  • one longterm-transaction-service-call using the low-api
  • one longterm-transaction-service-call using the high-api

The service-call itself is quite simple:

  • the private part is a string : Privat_Data_1 or Privat_Data_2
  • the public part is an integer : 1111 or 2222

The GOAL for this test is:

  • test the longterm-transaction-feature
  • test the BufferListCheckOptionC with and without default-value
  • test the callback-feature with and without error

CODE client

package main

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

func callback(ctx *MqContextC) {
  ctx.ReadT_START()
  myPrivateHandle := ctx.ReadC()
  ctx.ReadT_END()
  myServiceResult := ctx.ReadI()

  fmt.Fprintln(os.Stdout, fmt.Sprintf("myPrivateHandle=%s, myServiceResult=%d", myPrivateHandle, myServiceResult));
}

func main() {
  var ctx = MqContextC_New(nil)
  defer func() {
    if x := recover(); x != nil {
      ctx.ErrorCatch_1(x)
    }
    ctx.Exit_0()
  }()
  ctx.ConfigSetName("MyTransaction");

  // setup commandline arguments used for parsing
  args := MkBufferListCreateVC(os.Args)

  // check if the '--token' option is available, default "SRVC"
  token := args.CheckOptionC_2("--token", "SRVC")

  // connect to the server
  ctx.LinkCreate(args)

  // register callback
  ctx.ServiceCreate("CLB1", callback)

  // send block using the LOW-Api
  ctx.SendSTART()
  ctx.SendT_START()
  ctx.SendC("Privat_Data_1")
  ctx.SendT_END()
  ctx.SendI(11111)
  ctx.SendEND_AND_TRANSACTION_2(token, "CLB1")

  // send block using the HIGN-Api -> same as above, but shorter
  ctx.Send("T", "CLB1", token + ":(C)I", "Privat_Data_2", 22222)

  // now we wait for exact ONE result of the "ctx"
  ctx.ProcessEvent_1(MQ_WAIT_OWN)
}