hololinked.core.zmq.brokers.BaseZMQ
Base class for all ZMQ message brokers. Implements socket creation & logger which is common to all server and client implementations.
Source code in hololinked\core\zmq\brokers.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
|
Functions
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\core\zmq\brokers.py
get_socket
classmethod
get_socket(*, id: str, node_type: str, context: zmq.asyncio.Context | zmq.Context, transport: ZMQ_TRANSPORTS = ZMQ_TRANSPORTS.IPC, socket_type: zmq.SocketType = zmq.ROUTER, **kwargs) -> typing.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
|
Each ROUTER socket require unique identity to correctly route the messages. |
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 |
|
ZMQ_TRANSPORTS
|
TCP, IPC or INPROC. Message crafting/passing/routing is transport invariant as suggested by ZMQ. Speed relationship - INPROC > IPC > TCP. |
IPC
|
|
SocketType
|
Usually a ROUTER socket is implemented for both client-server and peer-to-peer communication |
ROUTER
|
|
|
{}
|
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 TCP, IPC or INPROC is used |
RuntimeError
|
if transport is TCP and a socket connect from client side is requested but a socket address is not supplied |
Source code in hololinked\core\zmq\brokers.py
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 |
|
hololinked.core.zmq.brokers.BaseAsyncZMQ
Bases: BaseZMQ
Base class for all async ZMQ servers and clients.
Source code in hololinked\core\zmq\brokers.py
Functions
create_socket
create_socket(*, id: str, node_type: str = 'server', context: zmq.asyncio.Context | None = None, transport: str = 'IPC', socket_type: zmq.SocketType = zmq.ROUTER, **kwargs) -> None
Overloads create_socket()
to create, bind/connect an async socket. A async context is created if none is supplied.
Source code in 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\core\zmq\brokers.py
Functions
create_socket
create_socket(*, id: str, node_type: str = 'server', context: zmq.Context | None = None, transport: str = 'IPC', socket_type: zmq.SocketType = zmq.ROUTER, **kwargs) -> None
Overloads create_socket()
to create, bind/connect a synchronous socket. A synchronous context is created
if none is supplied.
Source code in hololinked\core\zmq\brokers.py
hololinked.core.zmq.brokers.BaseZMQServer
Bases: BaseZMQ
Source code in hololinked\core\zmq\brokers.py
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
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 |
Returns:
Type | Description |
---|---|
None
|
|
Source code in 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
(parse_client_message()
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
RequestMessage
|
the client message parsing which the exception occurred |
required |
|
Exception
|
exception object raised |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in 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 |
Returns:
Type | Description |
---|---|
None
|
|
Source code in hololinked\core\zmq\brokers.py
handled_default_message_types
Handle default cases for the server. This method is called when the message type is not recognized or the message is not a valid message.
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 |
|
the socket to which the response must be sent. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in hololinked\core\zmq\brokers.py
handshake
Pass a handshake message to client. Absolutely mandatory to ensure initial messages do not get lost because of ZMQ's very 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 |
Returns:
Type | Description |
---|---|
None
|
|
Source code in hololinked\core\zmq\brokers.py
hololinked.core.zmq.brokers.BaseZMQClient
Bases: BaseZMQ
Base class for all ZMQ clients irrespective of sync and async.
server's response to client ::
[address, bytes(), server_type, message_type, message id, data, pre encoded data]|br|
[ 0 , 1 , 2 , 3 , 4 , 5 , 6 ]|br|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The instance name of the server (or |
required |
|
ZMQ or HTTP Server |
required | |
|
server type metadata |
required | |
|
custom implementation of ZMQ serializer if necessary |
required | |
|
custom implementation of JSON serializer if necessary |
required |
Source code in hololinked\core\zmq\brokers.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
|