BaseZMQ
hololinked.server.zmq.brokers.BaseZMQ
Base class for all ZMQ message brokers.
Implements socket creation & logger config, which are common to all server and client implementations.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
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 269 270 | |
Functions
__init__
Initialize the broker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
unique ID of the server/client. This is used as the identity of the ZMQ socket. |
required |
|
logger instance to use. If None, a default logger is created. |
required |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
exit
Cleanup method to terminate ZMQ sockets and contexts before quitting.
Called by __del__() automatically. Each subclass server/client should implement their version of
exiting if necessary.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
get_socket
classmethod
get_socket(*, server_id: str, socket_id: str, node_type: str, context: Context | Context, access_point: str = ZMQ_TRANSPORTS.IPC, socket_type: SocketType = zmq.SocketType.ROUTER, **kwargs) -> tuple[zmq.Socket | zmq.asyncio.Socket, str]
Create a socket with certain specifications.
Supported ZeroMQ transports are TCP, IPC & INPROC. For IPC sockets, a file is created under TEMP_DIR of global configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Used to create socket address |
required |
|
str
|
Each ROUTER socket require unique identity to correctly route the messages, usually same as |
required |
|
str
|
server or client? i.e. whether to bind (server) or connect (client) as per ZMQ definition |
required |
|
Context | Context
|
ZeroMQ Context object that creates the socket |
required |
|
str
|
|
IPC
|
|
SocketType
|
Usually a ROUTER socket is implemented for both client-server and peer-to-peer communication. But other sockets like PAIR, DEALER, etc. can also be used as per the use-case. |
ROUTER
|
|
Additional arguments:
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
socket |
Socket
|
created socket |
socket_address |
str
|
qualified address of the socket created for any transport type |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
NotImplementedError
|
if transport other than |
RuntimeError
|
if transport is |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
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 269 270 | |
hololinked.server.zmq.brokers.BaseAsyncZMQ
Bases: BaseZMQ
Base class for all async ZMQ servers and clients.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
Functions
create_socket
create_socket(*, server_id: str, socket_id: str, node_type: str = 'server', context: Context | None = None, access_point: str = ZMQ_TRANSPORTS.IPC, socket_type: SocketType = zmq.SocketType.ROUTER, **kwargs) -> None
Overloads create_socket() to create, bind/connect an async socket.
A global context is used if none is supplied.
Raises:
| Type | Description |
|---|---|
TypeError
|
if the supplied context is not an async ZMQ context |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
hololinked.server.zmq.brokers.BaseSyncZMQ
Bases: BaseZMQ
Base class for all sync ZMQ servers and clients.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
Functions
create_socket
create_socket(*, server_id: str, socket_id: str, node_type: str = 'server', context: Context | None = None, access_point: str = ZMQ_TRANSPORTS.IPC, socket_type: SocketType = zmq.SocketType.ROUTER, **kwargs) -> None
Overloads create_socket() to create, bind/connect a synchronous socket.
A global context is used if none is supplied.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
hololinked.server.zmq.brokers.BaseZMQServer
Bases: BaseZMQ
Base class for all ZMQ servers irrespective of sync and async.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
Functions
handle_error_message
Pass an exception message to the client when an exception occurred while executing the operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
RequestMessage
|
the client message for which the exception occurred |
required |
|
Exception
|
exception object raised |
required |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
handle_invalid_message
Pass an invalid message to the client when an exception occurred while parsing the message from the client (in handled_default_message_types()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
RequestMessage
|
the client message for which the parsing exception occurred |
required |
|
Exception
|
exception object raised |
required |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
handle_timeout
Pass timeout message to the client when the operation could not be executed within specified timeouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
RequestMessage
|
the client message which could not executed within the specified timeout. timeout value is generally specified within the execution context values. |
required |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
handled_default_message_types
Handle default cases for the server without further processing of the request (for example, HANDSHAKE).
This method is called once/supposed to be called when the message is received or popped out of the socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
RequestMessage
|
the client message to handle |
required |
Returns:
| Name | Type | Description |
|---|---|---|
handled |
bool
|
whether the message was handled here and needs no further processing |
Raises:
| Type | Description |
|---|---|
BreakLoop
|
if an |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
handshake
Pass a handshake message to client.
Absolutely mandatory to handshake with all clients to ensure initial messages do not get lost because of ZMQ's tiny but significant initial delay after creating socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
RequestMessage
|
the client message for which the handshake is being sent |
required |
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
hololinked.server.zmq.brokers.BaseZMQClient
Bases: BaseZMQ
Base class for all ZMQ clients irrespective of sync and async.
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | |
Attributes
poll_timeout
property
writable
Socket polling timeout in milliseconds greater than 0.
Functions
__init__
Initialize the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Unique id of the client to receive messages from the server. Each client connecting to same server must still have unique ID. |
required |
|
str
|
The server id to connect to |
required |
|
BoundLogger | None
|
logger instance to use. If None, a default logger is created. |
None
|
|
Additional arguments:
|
{}
|
Source code in repo/hololinked/hololinked/server/zmq/brokers.py
handled_default_message_types
Handle default cases for the client.
This method is called once/supposed to be called when the message is received or popped out of the socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ResponseMessage
|
the server message to handle |
required |
Returns:
| Name | Type | Description |
|---|---|---|
handled |
bool
|
whether the message was handled here and needs no further processing |
Raises:
| Type | Description |
|---|---|
ConnectionAbortedError
|
if the server disconnected |