Table Of Contents

Sending Messages Between Systems

Version:
    Last Modified: March 29, 2019

    Use messages to send commands and status updates or structure data, such as JSON, between systems and applications. Messages operate as a network queue, which uses the publish/subscribe model.

    What to Use

    What to Do

    1. Create the following diagram in a VI to subscribe to and read messages.

      Customize the gray sections for your unique programming goals.

      The Open Configuration node initiates a connection with a web server. Refer to the Details tab of the Open Configuration (User) or the Open Configuration (API Key) nodes for help connecting to a server.
      The Open node creates a message session with the web server, which allows you subscribe to a message queue.
      The Subscribe node registers an endpoint, such as a web application, to a specific topic.
      spd-note-note
      Note  

      Subscribers of a topic receive every message published to that topic beginning from the point they subscribe. They do not receive or have access to messages sent before that point.

      The Read node returns a message from the queue.
      If there are no queued messages, the call synchronously blocks up to the timeout specified or to the maximum timeout defined by the web server, whichever is smaller. If left unwired, the Read node has a default timeout of 100 milliseconds. In this example, the timeout is set to 2000 milliseconds.
      spd-note-note
      Note  

      Both NI Web Server and SystemLink Cloud have a maximum timeout of 10 seconds. To adjust this, edit the configuration file of the web server. Refer to Configuring NI Web Server more information.

      Use the Unflatten from JSON node when using the Read node to make messages easier to parse from a web browser.

      Use a While Loop to continue reading messages until a condition is met. In this example, the node reads messages until there is an error.

    2. Create the following diagram in a VI to publish messages.

      Customize the gray sections for your unique programming goals.

      The Open Configuration node initiates a connection with a web server. Refer to the Details tab of the Open Configuration (User) or the Open Configuration (API Key) nodes for help connecting to a server.
      The Open node creates a message session with the web server, allowing you to publish messages to a message queue.
      The Publish node publishes a message to a topic. If multiple messages are published, the subscriber reads the messages in the order they are received.

      Use the Flatten to JSON node when using the Publish node to make messages easier to parse from a web browser.

      Use a Case Structure to set up conditions for when to publish. In this example, the node publishes messages until you move the Publish switch to the off position on the panel.

      Use a While Loop to continue publishing tags until a condition is met. In this example, the node publishes messages until there is an error.

      The Close node terminates the message session with the web server.
      The Close Configuration node cleans up connections associated with the configuration by invalidating any open references to created objects.

    Troubleshooting

    If you encounter errors, try the following troubleshooting strategies:
    • Include the Subscribe node before a Read node. You must subscribe to a topic before your program will read a message.
    • Verify that you are subscribed to the right topic before running the code.
      spd-note-note
      Note  

      Topics are case sensitive.


    Recently Viewed Topics