Reference
SPA Distributed Application Tools package.
application
application
AbstractApplication
Bases: ApplicationLifeCycle
This provides a simple class for implementing a distributed application. It connects to a given message bus and provides a services for handling messages.
It provides a simple way to initialize ressources and handle sockets. It does not provide a concret implementation
for how the service behaves. This is left up to subclasses (see run_async method).
Attributes:
| Name | Type | Description |
|---|---|---|
async_callback |
A callback which is called upon receiving a message. |
|
config |
The configuration for the message bus. Can be any of the supported config types. |
|
ressources |
dict[str, SupportedContextManagers]
|
A list of context managers which are entered and exited during the livecycle |
_queue_in |
Queue
|
A queue for receiving messages from the message bus. |
Source code in spa_dat/application/application.py
17 18 19 20 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 | |
run_async
async
run_async()
Contains the logic how the applicaiton behaves (e.g. endless loop, etc.)
Source code in spa_dat/application/application.py
87 88 89 90 91 | |
setup
setup()
Method for initializing non async components/ressources of the application.
Source code in spa_dat/application/application.py
46 47 48 49 50 51 | |
start
start()
Start the asyncronous application. This method blocks until the application is stopped.
Source code in spa_dat/application/application.py
59 60 61 62 63 | |
start_async
async
start_async()
Initialize the application and its ressources.
Source code in spa_dat/application/application.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
teardown
teardown()
Method for cleanup non async components/ressources of the application.
Source code in spa_dat/application/application.py
53 54 55 56 57 | |
ConsumerApplication
Bases: AbstractApplication
Source code in spa_dat/application/application.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
run_async
async
run_async()
Repeats the callback on each received message
Source code in spa_dat/application/application.py
108 109 110 111 112 113 114 | |
DistributedApplication
This class provides a simple interface for creating distributed applications. It allows to create multiple applications which are connected to the same message bus. It does this by providing decorators for creating applications and producers.
Source code in spa_dat/application/application.py
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 | |
ProducerApplication
Bases: AbstractApplication
Source code in spa_dat/application/application.py
94 95 96 97 98 99 | |
run_async
async
run_async()
Starts the callback once and after it ends the producer is done.
Source code in spa_dat/application/application.py
95 96 97 98 99 | |
typedef
ApplicationLifeCycle
Bases: Protocol
Source code in spa_dat/application/typedef.py
17 18 19 20 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 | |
run_async
async
run_async()
Asyncronous method which contains the logic of the application. (e.g. endless loop, etc.)
Source code in spa_dat/application/typedef.py
36 37 38 39 40 | |
setup
setup()
Perform initialization tasks, such as setting up resources and dependencies
Source code in spa_dat/application/typedef.py
18 19 20 21 22 | |
start
start()
Execute your application - should block at this point
Source code in spa_dat/application/typedef.py
24 25 26 27 28 | |
start_async
async
start_async()
Asyncronous method which starts the application itself, not blocking
Source code in spa_dat/application/typedef.py
30 31 32 33 34 | |
teardown
teardown()
Handle cleanup
Source code in spa_dat/application/typedef.py
42 43 44 45 46 | |
protocol
kafka
KafkaSocket
Bases: SpaSocket, AbstractAsyncContextManager
Source code in spa_dat/protocol/kafka.py
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 | |
__aenter__
async
__aenter__()
Return self upon entering the runtime context.
Source code in spa_dat/protocol/kafka.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
__aexit__
async
__aexit__(exc_type, exc_value, traceback)
Raise any exception triggered within the runtime context.
Source code in spa_dat/protocol/kafka.py
132 133 134 135 136 137 138 139 140 141 142 143 144 | |
request
async
request(message: SpaMessage) -> SpaMessage | None
Publish a message and wait for a response. Returns none if no response was received / could not be parsed.
Source code in spa_dat/protocol/kafka.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
KafkaSocketProvider
Bases: SocketProvider
Source code in spa_dat/protocol/kafka.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
overwrite_config
overwrite_config(
topics: str | list[str] | None = None,
*kwargs: str | list[str] | None
) -> None
Overwrites the given config from any defaults which were provided earlier. This is useful if you want to construct or change the default config
Source code in spa_dat/protocol/kafka.py
195 196 197 198 199 200 201 202 203 204 | |
mqtt
MqttSocket
Bases: SpaSocket, AbstractAsyncContextManager
Defines an interface for an mqtt broker. It implements all necessary methods from the SpaProtocol.
Source code in spa_dat/protocol/mqtt.py
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 | |
__aenter__
async
__aenter__()
Return self upon entering the runtime context.
Source code in spa_dat/protocol/mqtt.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
__aexit__
async
__aexit__(exc_type, exc_value, traceback)
Raise any exception triggered within the runtime context.
Source code in spa_dat/protocol/mqtt.py
130 131 132 133 134 135 136 137 | |
build_client_config
build_client_config(client_id: str | None = None) -> dict
Build a client config for a new client. The client_id is overwritten from the default if specified.
Source code in spa_dat/protocol/mqtt.py
96 97 98 99 100 101 102 103 104 105 106 107 | |
request
async
request(message: SpaMessage) -> SpaMessage | None
Publish a message and wait for a response. Returns none if no response was received / could not be parsed.
Source code in spa_dat/protocol/mqtt.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
MqttSocketProvider
Bases: SocketProvider
Defines an interface for a socket provider. A socket provider is a function which creates a socket and returns it.
Source code in spa_dat/protocol/mqtt.py
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 | |
overwrite_config
overwrite_config(
topics: str | list[str] | None = None,
*kwargs: str | list[str] | None
) -> None
Overwrites the given config from any defaults which were provided earlier. This is useful if you want to construct or change the default config
Source code in spa_dat/protocol/mqtt.py
193 194 195 196 197 198 199 200 201 202 | |
typedef
SocketProvider
Bases: Protocol
A service provider is a class which creates a socket from a given configuration and returns it. It also allows to add a queue for communication
Source code in spa_dat/protocol/typedef.py
39 40 41 42 43 44 45 46 47 48 49 | |
SpaMessage
Bases: BaseModel
Defines the message for SPA applications
Source code in spa_dat/protocol/typedef.py
26 27 28 29 30 31 32 33 34 35 36 | |
SpaSocket
Bases: Protocol
Defines the interface for SPA applications to communicate with the message bus.
Source code in spa_dat/protocol/typedef.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
provider
SocketProviderFactory
Bases: Protocol
A service provider factory is a function which returns a service provider.
Source code in spa_dat/provider.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |