Skip to content

Commit 9581b30

Browse files
committed
docs(msgbus): add diagrams
1 parent 764c144 commit 9581b30

File tree

2 files changed

+146
-15
lines changed

2 files changed

+146
-15
lines changed

docs/docs/features/features.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Extended features add connectivity and monitoring capabilities:
9696

9797
- [olink](olink.md) - provides client and server adapters for the [ObjectLink](/docs/protocols/objectlink/intro) protocol. Use this to connect your Unreal application to remote services or the ApiGear simulation tools.
9898
- [msgbus](msgbus.md) - provides adapters using Unreal's built-in Message Bus for inter-process communication within the Unreal ecosystem.
99+
100+
> **Choosing between OLink and Message Bus?** See the [comparison guide](msgbus.md#when-to-use-message-bus-vs-olink) for a detailed breakdown.
101+
99102
- [monitor](monitor.md) - generates a middleware layer which logs all API events to the [CLI](/docs/cli/intro) or the [Studio](/docs/studio/intro).
100103

101104
### Test Features

docs/docs/features/msgbus.md

Lines changed: 143 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import helloWorldModuleComponent from '!!raw-loader!./data/helloworld.module.yam
1111

1212
# Message Bus
1313

14-
The `msgbus` feature provides client and adapter implementations using Unreal Engine's built-in [Message Bus](https://docs.unrealengine.com/5.0/en-US/API/Runtime/Messaging/IMessageBus/) system. This enables:
14+
The `msgbus` feature provides client and adapter implementations using Unreal Engine's built-in [Message Bus](https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Messaging/IMessageBus) system. This enables:
1515

1616
- **Inter-process communication**: Connect Unreal applications running on the same machine
1717
- **Editor-to-game communication**: Share data between editor tools and PIE sessions
@@ -68,20 +68,6 @@ The following file structure is generated in the `IoWorldMsgBus` module:
6868
┗ 📜IoWorldMsgBus.Build.cs
6969
```
7070

71-
## Message Protocol
72-
73-
The Message Bus feature uses generated message structures (`IoWorldHelloMsgBusMessages.h`) for communication between client and adapter. These messages handle:
74-
75-
- **Connection lifecycle** - service discovery, initialization, and disconnect
76-
- **Heartbeat monitoring** - ping/pong messages to detect connection health
77-
- **Property synchronization** - change requests and notifications
78-
- **Operation request/response** - calls with correlation IDs for matching replies
79-
- **Signal broadcasting** - events sent to all connected clients
80-
81-
:::note
82-
You don't need to interact with these message types directly - they are used internally by the client and adapter classes.
83-
:::
84-
8571
## Message Bus Client
8672

8773
The `UIoWorldHelloMsgBusClient` class implements `IIoWorldHelloInterface` and communicates with a remote adapter via Message Bus.
@@ -94,6 +80,32 @@ The `UIoWorldHelloMsgBusClient` class implements `IIoWorldHelloInterface` and co
9480
4. **Caches state**: Maintains local copies of properties synchronized from the adapter
9581
5. **Monitors health**: Tracks connection status with heartbeat ping/pong
9682

83+
```mermaid
84+
graph TB
85+
subgraph Local[" Your Application "]
86+
Code[Application Code]
87+
end
88+
89+
subgraph Client[" MsgBus Client "]
90+
Interface["IIoWorldHelloInterface"]
91+
end
92+
93+
subgraph Transport[" Message Bus "]
94+
Bus((UDP))
95+
end
96+
97+
subgraph Remote[" Remote "]
98+
Adapter[MsgBus Adapter]
99+
end
100+
101+
Code -->|uses| Interface
102+
Interface <-->|requests| Bus
103+
Bus -.->|updates| Interface
104+
Bus <-->|messages| Adapter
105+
```
106+
107+
*The client acts as a **Remote Proxy** - it implements the same interface as the backend service but forwards calls over Message Bus. Properties are cached locally for fast reads.*
108+
97109
### Connection Management
98110

99111
The client provides methods to manage the connection lifecycle:
@@ -168,6 +180,37 @@ The `UIoWorldHelloMsgBusAdapter` wraps a local `IIoWorldHelloInterface` implemen
168180
4. **Broadcasts updates**: Publishes property changes and signals to all subscribed clients
169181
5. **Tracks clients**: Monitors connected clients and handles timeouts
170182
183+
```mermaid
184+
graph BT
185+
subgraph Local[" Your Backend "]
186+
Impl["IIoWorldHelloInterface<br/>(your implementation)"]
187+
end
188+
189+
subgraph Adapter[" MsgBus Adapter "]
190+
Handler[Request Handler]
191+
end
192+
193+
subgraph Transport[" Message Bus "]
194+
Bus((UDP))
195+
end
196+
197+
subgraph Remote[" Remote Clients "]
198+
C1[Client 1]
199+
C2[Client 2]
200+
CN[Client N]
201+
end
202+
203+
Handler -->|calls| Impl
204+
Impl -.->|notifies| Handler
205+
206+
C1 & C2 & CN -->|requests| Bus
207+
Bus -->|forwards| Handler
208+
Handler -.->|broadcasts| Bus
209+
Bus -.->|updates| C1 & C2 & CN
210+
```
211+
212+
*The adapter uses the **Adapter Pattern** - it wraps any `IIoWorldHelloInterface` implementation and exposes it over Message Bus. Multiple clients can connect simultaneously.*
213+
171214
### Connection Management
172215

173216
The adapter provides methods to control when it accepts client connections:
@@ -261,3 +304,88 @@ UnrealEditor-Cmd.exe YourProject.uproject -ExecCmds="Automation RunTests IoWorld
261304
- For high-frequency updates, consider using direct connections
262305
- Property changes are only broadcast when values actually change
263306
- The client tracks sent values to avoid redundant network requests
307+
308+
## Message Protocol
309+
310+
The Message Bus feature uses generated message structures (`IoWorldHelloMsgBusMessages.h`) for communication between client and adapter. These messages handle:
311+
312+
- **Connection lifecycle** - service discovery, initialization, and disconnect
313+
- **Heartbeat monitoring** - ping/pong messages to detect connection health
314+
- **Property synchronization** - change requests and notifications
315+
- **Operation request/response** - calls with correlation IDs for matching replies
316+
- **Signal broadcasting** - events sent to all connected clients
317+
318+
:::note
319+
You don't need to interact with these message types directly - they are used internally by the client and adapter classes.
320+
:::
321+
322+
### Communication Flow
323+
324+
The following diagram shows how messages flow between client and adapter for each type of interaction:
325+
326+
```mermaid
327+
sequenceDiagram
328+
participant App as Application
329+
participant Client as MsgBusClient
330+
participant Bus as Message Bus
331+
participant Adapter as MsgBusAdapter
332+
participant Backend as Backend Service
333+
334+
rect rgb(240, 248, 255)
335+
Note over Client,Adapter: Service Discovery & Connection
336+
App->>Client: _Connect()
337+
Client->>Bus: Publish Discovery Message
338+
Bus->>Adapter: Discovery Message
339+
Adapter->>Bus: Publish Init Response (current state)
340+
Bus->>Client: Init Response
341+
Client->>Client: Cache initial properties
342+
Client->>App: _ConnectionStatusChanged(true)
343+
end
344+
345+
rect rgb(255, 250, 240)
346+
Note over Client,Adapter: Property Synchronization
347+
App->>Client: SetLast(newValue)
348+
Client->>Bus: Publish Property Change Request
349+
Bus->>Adapter: Property Change Request
350+
Adapter->>Backend: SetLast(newValue)
351+
Backend->>Backend: Update property
352+
Backend-->>Adapter: Property Changed
353+
Adapter->>Bus: Broadcast Property Changed
354+
Bus->>Client: Property Changed Notification
355+
Client->>Client: Update cache
356+
Client->>App: OnLastChanged delegate
357+
end
358+
359+
rect rgb(240, 255, 240)
360+
Note over Client,Adapter: Operation Request/Response
361+
App->>Client: Say(msg, when)
362+
Client->>Bus: Publish Operation Request (correlationId)
363+
Bus->>Adapter: Operation Request
364+
Adapter->>Backend: Say(msg, when)
365+
Backend-->>Adapter: Return result
366+
Adapter->>Bus: Publish Operation Response (correlationId)
367+
Bus->>Client: Operation Response
368+
Client->>Client: Match correlationId
369+
Client-->>App: Return result
370+
end
371+
372+
rect rgb(255, 240, 245)
373+
Note over Client,Adapter: Signal Broadcasting
374+
Backend->>Backend: Emit JustSaid signal
375+
Backend-->>Adapter: OnJustSaid
376+
Adapter->>Bus: Broadcast Signal
377+
Bus->>Client: Signal Notification
378+
Client->>App: OnJustSaidSignal delegate
379+
end
380+
381+
rect rgb(245, 245, 245)
382+
Note over Client,Adapter: Heartbeat Monitoring
383+
loop Every HeartbeatIntervalMS
384+
Client->>Bus: Publish Ping (timestamp)
385+
Bus->>Adapter: Ping
386+
Adapter->>Bus: Publish Pong (timestamp)
387+
Bus->>Client: Pong
388+
Client->>Client: Calculate RTT, update stats
389+
end
390+
end
391+
```

0 commit comments

Comments
 (0)