cortex.core.publisher¶
publisher ¶
Publisher implementation for Cortex.
Provides a ZeroMQ-based publisher that registers with the discovery daemon and publishes messages on IPC sockets using asyncio.
Classes¶
Publisher ¶
Sends typed messages on a topic over a ZMQ PUB socket.
On construction the publisher binds its own IPC socket, registers the
(topic, address, fingerprint) triple with the discovery daemon, and
becomes ready. :meth:publish is synchronous and non-blocking by default
— if the send queue is full the message is dropped and False is
returned.
Always create via :meth:Node.create_publisher; that path shares the
node's async context and tracks the publisher for clean shutdown.
Note
zmq.PUB sockets are not thread-safe. Do not call
:meth:publish concurrently from multiple threads or tasks on the
same :class:Publisher instance.
Example
Source code in src/cortex/core/publisher.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
Attributes¶
is_registered
property
¶
Check if publisher is registered with discovery daemon.
last_publish_time
property
¶
Get the timestamp of the last published message.
Functions¶
publish ¶
Serialize and send message on this topic.
Uses the frame-aware transport path so large NumPy / PyTorch buffers ride as separate ZMQ frames (zero-copy handoff).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Message
|
Instance whose class matches :attr: |
required |
flags
|
int
|
ZMQ send flags. Default :data: |
NOBLOCK
|
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
full ( |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/cortex/core/publisher.py
close ¶
Close the publisher and unregister from discovery.
Source code in src/cortex/core/publisher.py
Functions¶
generate_ipc_address ¶
Build the deterministic IPC endpoint for a (node, topic) pair.
The path lives under /tmp/cortex/topics/ and encodes the node name
and topic so that the same pair always produces the same socket file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic_name
|
str
|
Topic path, e.g. |
required |
node_name
|
str
|
Owning node's name. Must be unique per topic within the host — duplicate pairs would race on the socket file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A |