Solace Callback Message Operation Track - NodeJs +TypeScript

There are two things wrong with the SendMessageToSolaceTEST function you have provided.

First, you declare a local variable connectStatus which is used in your return statement at the bottom, but the Promise callbacks you have supplied are setting the value of this.connectStatus which means the local variable is never assigned any value other than "" .

Secondly, you are mix and matching async-await coding with Promise-based patterns. It would be better if the function works with one pattern or the other. As-written, you are not waiting for the solaceClient.connect() call to complete. Rather, the connect is triggered, and the function will return immediately.

Using async-await style, this function should look more like:


const SendMessageToSolaceTEST = async function (): Promise<string> {
  this.solaceClient = new SolaceClient();
  
  let connectStatus;

  try {
    await this.solaceClient.Connect();       // wait for the connection to finish
    connectStatus = "Connected to Solace!";  // assign the local variable, not the class-level one
  } catch (error) {
    connectStatus = `${error}!`;
  }

  return "sibendu" + connectStatus;
}

I have not yet looked at the SolaceClient.ts file.