BaseZMQ
hololinked.core.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 hololinked/hololinked/core/zmq/brokers.py
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 | |
Functions
__init__
id: str unique ID of the server/client. This is used as the identity of the ZMQ socket. logger: logging.Logger, optional logger instance to use. If None, a default logger is created.
Source code in hololinked/hololinked/core/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 hololinked/hololinked/core/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.ROUTER, **kwargs) -> tuple[zmq.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 |
|---|---|
NotImplementedError
|
if transport other than |
RuntimeError
|
if transport is |
Source code in hololinked/hololinked/core/zmq/brokers.py
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 | |
hololinked.core.zmq.brokers.BaseAsyncZMQ
Bases: BaseZMQ
Base class for all async ZMQ servers and clients.
Source code in hololinked/hololinked/core/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.ROUTER, **kwargs) -> None
Overloads create_socket() to create, bind/connect an async socket. A global context is used if
none is supplied.
Source code in hololinked/hololinked/core/zmq/brokers.py
hololinked.core.zmq.brokers.BaseSyncZMQ
Bases: BaseZMQ
Base class for all sync ZMQ servers and clients
Source code in hololinked/hololinked/core/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.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 hololinked/hololinked/core/zmq/brokers.py
hololinked.core.zmq.brokers.BaseZMQServer
Bases: BaseZMQ
Base class for all ZMQ servers irrespective of sync and async
Source code in hololinked/hololinked/core/zmq/brokers.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 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 | |
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 hololinked/hololinked/core/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 hololinked/hololinked/core/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 hololinked/hololinked/core/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 |
Source code in hololinked/hololinked/core/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 hololinked/hololinked/core/zmq/brokers.py
hololinked.core.zmq.brokers.BaseZMQClient
Bases: BaseZMQ
Base class for all ZMQ clients irrespective of sync and async
Source code in hololinked/hololinked/core/zmq/brokers.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
Functions
__init__
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 hololinked/hololinked/core/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 |