Skip to content

Bus Example

The Bus example is located in the examples/bus directory. This example shows how to collect a data metric to measure the rate at which messages are received in messages/second based on the number of messages received by the subscriber.

Note

This example is only available if you have installed the Development package.

For purely synchronous data publication and subscription, the Bus can be created without using a Scheduler, and topics do not have to be associated with a ThreadPool.

The following table describes the functions used to configure a publisher and subscriber:

Function Description Publisher Subscriber
async_pub_async_sub Demonstrates asynchronous data publication, which is received asynchronously by a subscriber Registers a callback function to publish data at a poll interval of one microsecond Registers a callback to receive data from the publisher
sync_pub_sub Demonstrates the use of a publisher to publish data synchronously

This is achieved without using a Scheduler or ThreadPool as the data is pushed synchronously to the subscriber
Synchronously pushes data Receives data on a registered callback function
sync_pub_pull_sub Demonstrates the use of a publisher to publish data synchronously

The data is then pulled by the subscriber

This is achieved without using a Scheduler or ThreadPool as the subscriber polls for data that is pushed by the publisher
Synchronously pushes data Pulls available data on the Bus
sync_pub_async_sub Demonstrates the use of a publisher to publish data synchronously, which is received asynchronously by a subscriber using a callback function Synchronously pushes data Data is delivered asynchronously
async_pub_pull_sub Demonstrates the use of a publisher to publish data asynchronously

The data is then pulled by the subscriber
Publishes data at a poll interval of one microsecond using a scheduled publisher callback Makes a call to pull data to check for the data available from the publisher on the Bus

The output for each configuration in the bus example includes the following information:

  • Start and stop time in milliseconds. This is the period used in collecting the metrics
  • Count. This is the number of messages received by the subscriber
  • Dropped. This is the number of messages that could not be read by the subscriber if the queue is full
  • Messages/second. This is the rate at which the subscriber received the messages

The output is similar to the following:

- - - - - - - async_pub_async_sub - - - - - -
Start: 1590512943861 Stop: 1590512944699 Count: 10011 Dropped: 0
 Messages/Second: 11946
- - - - - - - sync_pub_sub - - - - - -
Start: 1590512946199 Stop: 1590512946206 Count: 10000 Dropped: 0
 Messages/Second: 1428571
- - - - - - - sync_pub_pull_sub - - - - - -
Start: 1590512946707 Stop: 1590512946723 Count: 10000 Dropped: 0
 Messages/Second: 625000
- - - - - - - sync_pub_async_sub - - - - - -
Start: 1590512947223 Stop: 1590512947790 Count: 10000 Dropped: 0
 Messages/Second: 17636
- - - - - - - async_pub_pull_sub - - - - - -
Start: 1590512949290 Stop: 1590512949840 Count: 9423 Dropped: 0
 Messages/Second: 17132
Back to top