Callback Messages

A standard message can be thought of a one way 'send and forget' message. No feedback is received from the Worker that you are sending the message to. The sender doesn't know if the message was received, and doesn't wait for a reply.

A callback message on the other hand, sends a message to the case of a Worker, and then is able to receive a reply message back from the Worker that it sent the callback message to.

Callback messages exist in two forms: Synchronous and Asynchronous.

Synchronous Callback Message

A synchronous callback message is sent with Enqueue Callback Message.vi (poly) : Collect. This VI is a blocking VI which will wait until it receives a reply message back from the Worker that it sent the callback message to.

Asynchronous Callback Message

An asynchronous callback message is sent with Enqueue Callback Message.vi (poly) : Forget. This VI does not block execution while it waits for a reply message to be received from the Worker it sent the callback message to. Instead, the reply message is sent to another case of the Worker that sent the callback message, so that the Worker that sent the callback message can continue execution, yet still receive a reply message at a later time.

How to send a callback message

Step 1: Create a case to receive the callback message

First you need to create a case in a Worker's MHL to receive a callback message. This is as simple as adding a new case to a case structure, with the name of the case of your choice. For this example, let's create a new case in a Worker's MHL called <Receive Message and Send Reply>, as shown below.

Within this case, we need to use the Workers palette VI: Callback Easy Reply.vi which will send a reply message back to the Worker that it receives the callback message from, containing (optionally) any data required within the reply message. The inputs to this VI include:

  • Data (variant): any data that you want to send along with the reply message.

  • Auxiliary (variant): any additional data that you want to send along with the reply message (not shown above)

In the example above, a string will be sent along with the reply message back to the Worker that sent this Worker the callback message.

Step 2: Send a callback message to the case we just created

We now want to send a callback message to the case we created above in Step 1. To do this, we can drop the Workers palette VI: Enqueue Callback Message.vi (poly) into the case of a Worker that has access to the message queue of the Worker we want to send the message to.

This example uses the synchronous VI Enqueue Callback Message.vi (poly) : Collect.

So let's say the MHL case in Step 1 belongs to Worker A. Therefore, as shown below, we would wire up the Enqueue Callback Message.vi with the following inputs:

  • Recipient Worker's Queue (Message Queue): the message queue of the Worker that you want to send the callback message to.

  • Recipient Worker's Case (String): the case of the Worker that will receive the callback message, defined as a string, wrapped in a Case Label.

  • Data (variant): any data that you want to send along with the callback message (not shown above).

  • Priority (enum): the priority of the callback message (not shown above)

  • Auxiliary (variant): any additional data that you want to send along with the callback message (not shown above)

  • Timeout in ms (int32): the timeout value that this VI will wait until it receives a reply message.

The sequence of events that will happen once the callback message is sent is:

  1. Callback message is sent to the <Receive Message and Send Reply> case of Worker A. Enqueue Callback Message.vi : Collect will wait until it receives a reply message back from Worker A.

  2. Worker A's <Receive Message and Send Reply> case receives the callback message. Within this case, by use of the Callback Easy Reply.vi, a string is sent back to the Worker that sent this case the callback message.

  3. Enqueue Callback Message.vi receives the reply message from Worker A's <Receive Message and Send Reply> case. This data is sent as a variant and therefore needs to be converted to the correct data type.

This completes the sending of a callback message within the framework.

The Fundamentals sample project demonstrates how to send callback messages with the Enqueue Callback Message.vi.

Last updated