h-message-bus 0.0.21__py3-none-any.whl → 0.0.23__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.
- h_message_bus/adapters/nats_publisher_adapter.py +10 -5
- h_message_bus/adapters/nats_subscriber_adapter.py +3 -2
- h_message_bus/application/message_publisher.py +1 -1
- h_message_bus/infrastructure/nats_client_repository.py +10 -1
- {h_message_bus-0.0.21.dist-info → h_message_bus-0.0.23.dist-info}/METADATA +1 -1
- {h_message_bus-0.0.21.dist-info → h_message_bus-0.0.23.dist-info}/RECORD +8 -8
- {h_message_bus-0.0.21.dist-info → h_message_bus-0.0.23.dist-info}/WHEEL +0 -0
- {h_message_bus-0.0.21.dist-info → h_message_bus-0.0.23.dist-info}/top_level.txt +0 -0
@@ -23,12 +23,17 @@ class NatsPublisherAdapter(MessagePublisher):
|
|
23
23
|
def __init__(self, nats_client: NatsClientRepository):
|
24
24
|
self.nats_client = nats_client
|
25
25
|
|
26
|
-
async def publish(self, message: HaiMessage)
|
26
|
+
async def publish(self, message: HaiMessage):
|
27
27
|
"""Publish a message to NATS."""
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
try:
|
29
|
+
|
30
|
+
await self.nats_client.publish(
|
31
|
+
message.topic,
|
32
|
+
message.to_json().encode()
|
33
|
+
)
|
34
|
+
except Exception as e:
|
35
|
+
print(f"Failed to publish message: {e}")
|
36
|
+
return
|
32
37
|
|
33
38
|
async def request(self, message: HaiMessage, timeout: float = 2.0) -> Optional[HaiMessage]:
|
34
39
|
"""Send a request and wait for a response."""
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Dict
|
1
|
+
from typing import Dict, Any
|
2
2
|
|
3
3
|
from ..adapters.nats_message_adapter import NatsMessageAdapter
|
4
4
|
from ..application.message_processor import MessageProcessor
|
@@ -30,7 +30,7 @@ class NatsSubscriberAdapter(MessageSubscriber):
|
|
30
30
|
self.subscriptions = []
|
31
31
|
self.adapters: Dict[str, NatsMessageAdapter] = {}
|
32
32
|
|
33
|
-
async def subscribe(self, topic: str, processor: MessageProcessor) ->
|
33
|
+
async def subscribe(self, topic: str, processor: MessageProcessor) -> Any:
|
34
34
|
"""Subscribe to a topic with a message handler."""
|
35
35
|
# Create an adapter for this use case
|
36
36
|
message_adapter = NatsMessageAdapter(processor)
|
@@ -43,6 +43,7 @@ class NatsSubscriberAdapter(MessageSubscriber):
|
|
43
43
|
)
|
44
44
|
|
45
45
|
self.subscriptions.append(subscription)
|
46
|
+
return subscription
|
46
47
|
|
47
48
|
async def unsubscribe_all(self) -> None:
|
48
49
|
"""Unsubscribe from all subscriptions."""
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import logging
|
1
2
|
from typing import Optional, Callable, Any
|
2
3
|
|
3
4
|
import nats
|
@@ -30,11 +31,13 @@ class NatsClientRepository:
|
|
30
31
|
self.client: NatsClient | None = None
|
31
32
|
|
32
33
|
self.subscriptions = []
|
34
|
+
self.logger = logging.getLogger(__name__)
|
33
35
|
|
34
36
|
async def connect(self) -> None:
|
35
37
|
"""Connect to NATS server."""
|
36
38
|
if self.client and self.client.is_connected:
|
37
39
|
return
|
40
|
+
self.logger.info(f"Connecting to NATS server at {self.config.server}")
|
38
41
|
|
39
42
|
self.client = await nats.connect(
|
40
43
|
servers=self.config.server,
|
@@ -50,7 +53,13 @@ class NatsClientRepository:
|
|
50
53
|
if not self.client or not self.client.is_connected:
|
51
54
|
await self.connect()
|
52
55
|
|
53
|
-
|
56
|
+
try:
|
57
|
+
result = await self.client.publish(subject, payload)
|
58
|
+
print(f"Message published: {result}")
|
59
|
+
self.logger.info(f"Successfully published message to subject: {subject}")
|
60
|
+
except Exception as e:
|
61
|
+
print(f"Failed to publish message: {e}")
|
62
|
+
return
|
54
63
|
|
55
64
|
async def subscribe(self, subject: str, callback: Callable) -> Any:
|
56
65
|
"""Subscribe to a subject with a callback."""
|
@@ -2,11 +2,11 @@ __init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
h_message_bus/__init__.py,sha256=T_07sHtXLlRuLwK-BRVfFIIOGc48TKbtVLvKtIw2K5U,516
|
3
3
|
h_message_bus/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
h_message_bus/adapters/nats_message_adapter.py,sha256=-hzx0UJmKJT4VWfRA_zVT68hddl9dejvUiSdLU1rY-w,1378
|
5
|
-
h_message_bus/adapters/nats_publisher_adapter.py,sha256=
|
6
|
-
h_message_bus/adapters/nats_subscriber_adapter.py,sha256=
|
5
|
+
h_message_bus/adapters/nats_publisher_adapter.py,sha256=kIh7J-eS-MPvfGsnmdGwsWYfLgepBC99v5d04KXyOaE,1900
|
6
|
+
h_message_bus/adapters/nats_subscriber_adapter.py,sha256=UJN2Es7hokbO5YsSUAf0KQ2B15QcGzGtQx-G1S3iQWQ,2105
|
7
7
|
h_message_bus/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
h_message_bus/application/message_processor.py,sha256=1vdVfPn1BUDmswJ-Y5aS-YDbLSizrjX6_CMIBa5SGjc,734
|
9
|
-
h_message_bus/application/message_publisher.py,sha256=
|
9
|
+
h_message_bus/application/message_publisher.py,sha256=pYX4JzJLe7L_59gKVYBLqT6iTwFB73zhbzxd7yv2TqI,834
|
10
10
|
h_message_bus/application/message_subcriber.py,sha256=2yqUUHVHtZlA6-zzyHzghdWQ7ZmdcFic5c0xi_rgG-M,741
|
11
11
|
h_message_bus/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
12
|
h_message_bus/domain/event_messages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -30,9 +30,9 @@ h_message_bus/domain/request_messages/vector_save_request_message.py,sha256=NvRd
|
|
30
30
|
h_message_bus/domain/request_messages/web_get_docs_request_message.py,sha256=MkJySkRBlQ2CacMoPCd3FwXQt1tVVFdrZKxsA6yMsrk,1576
|
31
31
|
h_message_bus/domain/request_messages/web_search_request_message.py,sha256=ZoB4idrFEs7HQ6IRxmwKrrfHWe3GlGF4LuOK68K5NEM,1000
|
32
32
|
h_message_bus/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
h_message_bus/infrastructure/nats_client_repository.py,sha256=
|
33
|
+
h_message_bus/infrastructure/nats_client_repository.py,sha256=vfI7z0UYZ00qAhMDQNKZshOhyAEz7P8uC_edDH6Ox7M,3789
|
34
34
|
h_message_bus/infrastructure/nats_config.py,sha256=Yzqqd1bCfmUv_4FOnA1dvqIpakzV0BUL2_nXQcndWvo,1304
|
35
|
-
h_message_bus-0.0.
|
36
|
-
h_message_bus-0.0.
|
37
|
-
h_message_bus-0.0.
|
38
|
-
h_message_bus-0.0.
|
35
|
+
h_message_bus-0.0.23.dist-info/METADATA,sha256=P5izMs30tx2CRmfoUgsSeFwd6Zp9ufEewu9uayobQ3w,8834
|
36
|
+
h_message_bus-0.0.23.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
37
|
+
h_message_bus-0.0.23.dist-info/top_level.txt,sha256=BArjhm_lwFR9yJJEIf-LT_X64psuLkXFdbpQRJUreFE,23
|
38
|
+
h_message_bus-0.0.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|