zenbroker 0.1__py3-none-any.whl → 0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zenbroker/__init__.py +7 -0
- zenbroker/client.py +44 -0
- {zenbroker-0.1.dist-info → zenbroker-0.3.dist-info}/METADATA +1 -1
- zenbroker-0.3.dist-info/RECORD +6 -0
- zenbroker-0.3.dist-info/top_level.txt +1 -0
- zenbroker-0.1.dist-info/RECORD +0 -4
- zenbroker-0.1.dist-info/top_level.txt +0 -1
- {zenbroker-0.1.dist-info → zenbroker-0.3.dist-info}/WHEEL +0 -0
zenbroker/__init__.py
ADDED
zenbroker/client.py
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
import httpx
|
2
|
+
from typing import Dict, Any
|
3
|
+
from pydantic import BaseModel, Field, HttpUrl
|
4
|
+
|
5
|
+
class ZenbrokerClientOptions(BaseModel):
|
6
|
+
base_url: HttpUrl = Field(..., description="URL of the broker service.")
|
7
|
+
application_id: str = Field(..., description="Application ID")
|
8
|
+
|
9
|
+
class PostPublishEventPayload(BaseModel):
|
10
|
+
applicationId: str = Field(..., description="Application ID")
|
11
|
+
channel: str = Field(..., description="ChannelID")
|
12
|
+
data: Dict[str, Any]
|
13
|
+
|
14
|
+
class PostPublishEventResponse(BaseModel):
|
15
|
+
message: str = Field(..., description="Message from the server")
|
16
|
+
id: str = Field(..., description="ID of the message")
|
17
|
+
|
18
|
+
class ZenbrokerClient:
|
19
|
+
def __init__(self, opts: ZenbrokerClientOptions) -> None:
|
20
|
+
self._url: str = str(opts.base_url)
|
21
|
+
self._application_id: str = str(opts.application_id)
|
22
|
+
|
23
|
+
self._api = httpx.Client(base_url=self._url)
|
24
|
+
|
25
|
+
def publish(self, channel: str, data: Dict[str, Any]) -> PostPublishEventResponse:
|
26
|
+
post_data: PostPublishEventPayload = PostPublishEventPayload(
|
27
|
+
applicationId=self._application_id,
|
28
|
+
channel=channel,
|
29
|
+
data=data
|
30
|
+
)
|
31
|
+
|
32
|
+
response = self._api.post(
|
33
|
+
url="/producer/emit",
|
34
|
+
json=post_data.model_dump()
|
35
|
+
)
|
36
|
+
|
37
|
+
response.raise_for_status()
|
38
|
+
result = response.json()
|
39
|
+
|
40
|
+
return PostPublishEventResponse(
|
41
|
+
id=result.id,
|
42
|
+
message=result.message
|
43
|
+
)
|
44
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
zenbroker/__init__.py,sha256=i7O6N_4p6LuYKp8uc6UohCELn2TI523-oNf97F_Kbjw,184
|
2
|
+
zenbroker/client.py,sha256=uunO-cQwj8WR25RyKqc1o19Bge_eA9QWqQBbayHmAPY,1459
|
3
|
+
zenbroker-0.3.dist-info/METADATA,sha256=Rmeyd4FwOoD7xqzsTjW1yO2ycG2DeSNpJKjNLkC4CHo,206
|
4
|
+
zenbroker-0.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
5
|
+
zenbroker-0.3.dist-info/top_level.txt,sha256=u-V5a1mTLsnD3DQb01LQo8WtbYc75BIZ6jSWrZ7vDkY,10
|
6
|
+
zenbroker-0.3.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
zenbroker
|
zenbroker-0.1.dist-info/RECORD
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
zenbroker-0.1.dist-info/METADATA,sha256=HQDVqB3JdItofl09sTSCk9Vnj1ZL_1qLPV6S_z2McwU,206
|
2
|
-
zenbroker-0.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
3
|
-
zenbroker-0.1.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
4
|
-
zenbroker-0.1.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
|
File without changes
|