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

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

#include "msgque_mq.h"

static enum MkErrorE callback( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqReadT_START_E(mqctx);
  MK_STRN myPrivateHandle = MqReadC_e(mqctx);
  MqReadT_END(mqctx);
  MK_INT myServiceResult = MqReadI_e(mqctx);

  fprintf(stdout,"myPrivateHandle=%s, myServiceResult=%d\n", myPrivateHandle, myServiceResult);
  fflush(stdout);

error:
  return MkErrorStack_E(mqctx);
}

int main (int argc, MK_STRN argv[]) 
{
  MkRtSetup_NULL;

  MQ_CTX ctx = MqContextCreate(NULL,NULL);

  MqConfigSetName(ctx, "MyTransaction");

  // setup commandline arguments used for parsing
  MK_BFL args = MkBufferListCreateVC(argc, argv);

  // check if the '--token' option is available, default "SRVC"
  MK_STRN token = MkBufferListCheckOptionC_e(args, "--token", "SRVC", true);

  // connect to the server
  MqLinkCreate_E(ctx, args);

  // register callback
  MqServiceCreate_E(ctx, "CLB1", callback, NULL, NULL, NULL);
   
  // send block using the LOW-Api
  MqSendSTART_E(ctx);
  MqSendT_START_E(ctx);
  MqSendC_E(ctx, "Privat_Data_1");
  MqSendT_END_E(ctx);
  MqSendI_E(ctx, 11111);
  MqSendEND_AND_TRANSACTION_E(ctx, token, "CLB1", MK_TIMEOUT_DEFAULT);
   
  // send block using the HIGN-Api -> same as above, but shorter
  char buffer[30];
  sprintf(buffer, "%s:(C)I",token);
  MqSend_E(ctx, "T", "CLB1", buffer, "Privat_Data_2", 22222);
   
  // now we wait for exact ONE result of the "ctx"
  MqProcessEvent_E(ctx, MQ_WAIT_OWN, MK_TIMEOUT_DEFAULT);

error:
  MkBufferListDelete(args);
  // delete the context using the libmqmsgque APPLICATION-DTOR function "MqExit_1"
  MqExit_1(ctx);
}