PubSub
PubSub is a different communication model from client-server. A publisher sends sets of values as network messages; subscribers pick the messages they’re interested in. There’s no session between them, so many subscribers can receive the same message at once. Part 14 defines PubSub.
Building blocks
Section titled “Building blocks”Publisher Subscriber+--------------------------------------+ +--------------------------------+| PubSubConnection (PublisherId) | | PubSubConnection || WriterGroup (WriterGroupId) | NetworkMessage | ReaderGroup || DataSetWriter (DataSetWriterId) ---+-----------------> | DataSetReader || PublishedDataSet (fields) | UDP or broker | filter: PublisherId, |+--------------------------------------+ | WriterGroupId, WriterId | +--------------------------------+| Component | Role |
|---|---|
| PublishedDataSet | The fields to publish and where their values come from |
| DataSetWriter | Encodes a DataSet into DataSetMessages; identified by its DataSetWriterId |
| WriterGroup | Bundles the messages of several DataSetWriters into one NetworkMessage and sets the publishing interval; identified by its WriterGroupId |
| PubSubConnection | Holds the transport address and the PublisherId |
| DataSetReader | On the subscriber side, selects messages by PublisherId, WriterGroupId and DataSetWriterId and decodes their fields |
| DataSetMetaData | Field names and types, and the configuration version (major and minor) |
Messages
Section titled “Messages”A NetworkMessage consists of a header and one or more DataSetMessages:
- NetworkMessage header: PublisherId, group header (WriterGroupId, GroupVersion, NetworkMessageNumber, SequenceNumber), the list of DataSetWriterIds it carries and a security header.
- DataSetMessage: sequence number, status, configuration version, timestamp and fields. A key frame carries all fields; a delta frame carries only changed fields; there are also event and keep-alive messages.
There are two message mappings:
| Mapping | Format | Characteristics |
|---|---|---|
| UADP | Binary | Compact and fast; header fields are switched on and off with bit flags. |
| JSON | Text | Easy to read and to connect to IT systems. |
Transports
Section titled “Transports”| Transport | Address | Characteristics |
|---|---|---|
| UDP | opc.udp://host:port, default port 4840 |
No broker; unicast or multicast. |
| MQTT | A broker address and a topic | The broker forwards messages to subscribers; QoS sets the delivery guarantee. |
| AMQP | A broker address and a queue | Broker-based transport. |
Security and the SKS
Section titled “Security and the SKS”PubSub messages are signed, or signed and encrypted, with symmetric keys. Publishers and subscribers must share the keys of the same security group. A Security Key Service (SKS) distributes those keys: publishers and subscribers call the GetSecurityKeys method on the SKS server to get the current and upcoming keys, and switch to new keys when the key lifetime ends. The message security header carries the security token ID and a nonce.
With a broker transport, you can also protect the broker connection itself with TLS. That protection is separate from message security.
PubSub in the PDComm simulator
Section titled “PubSub in the PDComm simulator”The PubSub workspace of the PDComm simulator works with these settings:
| Item | Value |
|---|---|
| Message mapping | UADP |
| Transport | UDP unicast, MQTT 5 (QoS 1) |
| Role | Publisher and subscriber (loopback in one process), publisher, subscriber |
| DataSetMessage | Key frames whose fields are Variant values |
| Identifiers | PublisherId (UInt16, default 77), WriterGroupId (default 1), DataSetWriterId (default 17) |
| Received messages | Up to 256 kept; take them with pubsub_received |
The simulator exchanges UADP messages with security mode None, that is, without signatures or encryption.
Try it in the UDP PubSub tutorial and the MQTT PubSub tutorial.
Next steps
Section titled “Next steps”That’s all the background you need. Make your first connection with the quickstart.