Let’s get Go’ing with DDS in 2019! I am so excited to share that there is a new and quick way to develop a DDS application in Go! RTI Go Connector now provides a simplified API for easy DDS development as we’ve done with Connectors for Python and Javascript. If you have already used RTI Connector, you can quickly ramp up as it follows the same convention. If you haven’t used RTI Connector, please check out how-to tips in this blog!
Before jumping into RTI Go Connector, I would like to talk a little bit about the Go programming language. Go is an open source programming language designed for building simple, fast, and reliable software. While the syntax of Go is similar to dynamically-typed languages for ease of use, it is a statically-typed, compiled language for high performance, efficiency and safety. Go also supports built-in concurrency features to easily maximize the capabilities of multi-core networked computers. Although Go is relatively young (created in 2009), there are already many frameworks, libraries and software developed. You can find a curated project list for Go here.
With RTI Go Connector, you can easily integrate RTI Connext DDS with lots of other technologies already developed and available in Go.
The motivation for us to develop Go Connector was to integrate RTI Connext DDS with InfluxDB (the time-series database for monitoring). We could quickly develop DDS plugins for Telegraf (a plugin-driven monitoring agent for InfluxDB) using Go Connector. The size of plugin code is roughly a mere 100 lines.
To give you an idea how Go Connector API works, I would like to go over a simple writer example.
The first thing you need to do is to import the Connector package.
import "github.com/rticommunity/rticonnextdds-connector-go"
After that, you can create a connector object by calling the “NewConnector” function. To create a connector object, you have to provide an XML-Based App Creation configuration file and the name of a DDS Participant defined in the XML configuration file. Go provides an interesting primitive called defer. As it is named, a defer statement delays the execution of a function until the surrounding function returns. You can then call “Delete” function to delete the created connector object right after the NewConnector function.
connector, err := rti.NewConnector("MyParticipantLibrary::Zero", filepath)
defer connector.Delete()
You need a connector output object to write a sample. To get an output object, you need to pass the name of a DDS DataWriter defined in the XML configuration file.
output, err := connector.GetOutput("MyPublisher::MySquareWriter")
Next, you can set fields in a sample instance. Connector provides set functions for all primitives types supported in Go.
output.Instance.SetInt("x", 1)
output.Instance.SetInt("y", 2)
output.Instance.SetInt("shapesize", 30)
output.Instance.SetString("color", "BLUE")
Finally, you can write the sample.
output.Write();
This describes a simple example of how to publish DDS data with Go Connector. Basically, you need four steps:
- Create a connector object
- Get an output object
- Set values to a sample
- Write the sample
You can also set values directly to Go structs. Go offers built-in support for JSON encoding and decoding, and Go Connector utilizes functions provided by Connext API for converting DDS to JSON vice versa to do this.
type Shape struct {
Color string `json:"color"`
X int `json:"x"`
Y int `json:"y"`
Shapesize int `json:"shapesize"`
}
var shape Shape
shape.Y = 2
output.Instance.Set(&shape)
If you are interested in learning more about the new Go Connector, please refer to the following GitHub. It describes how to get started and provides simple examples.
https://github.com/rticommunity/rticonnextdds-connector-go
Let us know on our RTI Community forum if you have any questions. Happy coding!
Posts by Tag
- Developers/Engineer (174)
- Connext DDS Suite (77)
- Technology (74)
- News & Events (71)
- 2020 (54)
- Standards & Consortia (51)
- Aerospace & Defense (47)
- 2023 (35)
- Automotive (34)
- 2022 (29)
- IIoT (27)
- Leadership (24)
- 2024 (22)
- Cybersecurity (20)
- Healthcare (20)
- 2021 (19)
- Military Avionics (15)
- Culture & Careers (14)
- FACE (13)
- Connectivity Technology (11)
- Connext DDS Pro (10)
- JADC2 (10)
- ROS 2 (10)
- Connext DDS Tools (7)
- Connext DDS Micro (6)
- Databus (6)
- Transportation (5)
- Case + Code (4)
- Connext DDS (4)
- Connext DDS Cert (4)
- Energy Systems (4)
- FACE Technical Standard (4)
- Oil & Gas (3)
- RTI Labs (3)
- Research (3)
- Robotics (3)
- #A&D (2)
- Connext Conference (2)
- Edge Computing (2)
- MDO (2)
- MS&T (2)
- TSN (2)
- ABMS (1)
- C4ISR (1)
- ISO 26262 (1)
- L3Harris (1)
- LabView (1)
- MathWorks (1)
- National Instruments (1)
- Simulation (1)
- Tech Talks (1)
- UAM (1)
- Videos (1)
- eVTOL (1)