h-message-bus 0.0.22__py3-none-any.whl → 0.0.24__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 +3 -2
- h_message_bus/adapters/nats_subscriber_adapter.py +3 -2
- h_message_bus/domain/request_messages/vector_save_request_message.py +8 -1
- h_message_bus/infrastructure/nats_client_repository.py +8 -1
- {h_message_bus-0.0.22.dist-info → h_message_bus-0.0.24.dist-info}/METADATA +1 -1
- {h_message_bus-0.0.22.dist-info → h_message_bus-0.0.24.dist-info}/RECORD +8 -8
- {h_message_bus-0.0.22.dist-info → h_message_bus-0.0.24.dist-info}/WHEEL +1 -1
- {h_message_bus-0.0.22.dist-info → h_message_bus-0.0.24.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,4 @@
|
|
1
|
+
import asyncio
|
1
2
|
from typing import Optional
|
2
3
|
|
3
4
|
from ..application.message_publisher import MessagePublisher
|
@@ -23,14 +24,14 @@ class NatsPublisherAdapter(MessagePublisher):
|
|
23
24
|
def __init__(self, nats_client: NatsClientRepository):
|
24
25
|
self.nats_client = nats_client
|
25
26
|
|
26
|
-
async def publish(self, message: HaiMessage):
|
27
|
+
async def publish(self, message: HaiMessage, wait_time: float = 0.1):
|
27
28
|
"""Publish a message to NATS."""
|
28
29
|
try:
|
29
|
-
|
30
30
|
await self.nats_client.publish(
|
31
31
|
message.topic,
|
32
32
|
message.to_json().encode()
|
33
33
|
)
|
34
|
+
await asyncio.sleep(wait_time)
|
34
35
|
except Exception as e:
|
35
36
|
print(f"Failed to publish message: {e}")
|
36
37
|
return
|
@@ -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."""
|
@@ -14,12 +14,13 @@ class VectorSaveRequestMessage(HaiMessage):
|
|
14
14
|
return super().create(topic=topic, payload=payload)
|
15
15
|
|
16
16
|
@classmethod
|
17
|
-
def create_message(cls, collection_name: str, document_id: str, content: str, metadata: dict[str,str]) -> 'VectorSaveRequestMessage':
|
17
|
+
def create_message(cls, collection_name: str, collection_metadata: dict[str,str], document_id: str, content: str, metadata: dict[str,str]) -> 'VectorSaveRequestMessage':
|
18
18
|
"""Create a message requesting Twitter user data"""
|
19
19
|
return cls.create(
|
20
20
|
topic=RequestMessageTopic.VECTORS_SAVE,
|
21
21
|
payload={
|
22
22
|
"collection_name": collection_name,
|
23
|
+
"collection_metadata": collection_metadata,
|
23
24
|
"document_id": document_id,
|
24
25
|
"content": content,
|
25
26
|
"metadata": metadata
|
@@ -31,6 +32,11 @@ class VectorSaveRequestMessage(HaiMessage):
|
|
31
32
|
"""Get the collection name from the payload"""
|
32
33
|
return self.payload.get("collection_name")
|
33
34
|
|
35
|
+
@property
|
36
|
+
def collection_metadata(self) -> str:
|
37
|
+
"""Get the collection name from the payload"""
|
38
|
+
return self.payload.get("collection_metadata")
|
39
|
+
|
34
40
|
@property
|
35
41
|
def document_id(self) -> str:
|
36
42
|
"""Get the document ID from the payload"""
|
@@ -53,6 +59,7 @@ class VectorSaveRequestMessage(HaiMessage):
|
|
53
59
|
|
54
60
|
return cls.create_message(
|
55
61
|
collection_name=payload.get("collection_name", ''),
|
62
|
+
collection_metadata=payload.get("collection_metadata", {}),
|
56
63
|
document_id=payload.get("document_id", ''),
|
57
64
|
content=payload.get("content", ''),
|
58
65
|
metadata=payload.get("metadata", {})
|
@@ -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,11 @@ 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
|
+
await self.client.publish(subject, payload)
|
58
|
+
except Exception as e:
|
59
|
+
print(f"Failed to publish message: {e}")
|
60
|
+
return
|
54
61
|
|
55
62
|
async def subscribe(self, subject: str, callback: Callable) -> Any:
|
56
63
|
"""Subscribe to a subject with a callback."""
|
@@ -2,8 +2,8 @@ __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=EgrGioGuZfLpJsb5wiialMGMe8E4oUktS8zMdGri3Lc,1982
|
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
9
|
h_message_bus/application/message_publisher.py,sha256=pYX4JzJLe7L_59gKVYBLqT6iTwFB73zhbzxd7yv2TqI,834
|
@@ -26,13 +26,13 @@ h_message_bus/domain/request_messages/vector_query_collection_request_message.py
|
|
26
26
|
h_message_bus/domain/request_messages/vector_query_collection_response_message.py,sha256=Q589JT_QE-oVsTh1GEmK__3Hct7ijfM1UTcPi0YTGn8,1767
|
27
27
|
h_message_bus/domain/request_messages/vector_read_metadata_request_message.py,sha256=P9t6pcynS112F9_Jmbvw8wlfXhs5NOnV48SUVq92xt8,873
|
28
28
|
h_message_bus/domain/request_messages/vector_read_metadata_response_message.py,sha256=G2TDV_lbUM7RVrvEaYQAP-3I36J0pqLXqxnqwVBMWhk,1648
|
29
|
-
h_message_bus/domain/request_messages/vector_save_request_message.py,sha256=
|
29
|
+
h_message_bus/domain/request_messages/vector_save_request_message.py,sha256=Omq0zzUUDz7bp1-3shsTrVn_V45Tt43rq_QqRNaE0FM,2457
|
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=bhaWRK94h2EmFIef2DALnoBJKnuTnx6-iU7IXO2S_EU,3642
|
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.24.dist-info/METADATA,sha256=mmaUjeM70bJVT5s3W1MRp1cvqvPYuN7T-aXPqOlyZFs,8834
|
36
|
+
h_message_bus-0.0.24.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
37
|
+
h_message_bus-0.0.24.dist-info/top_level.txt,sha256=BArjhm_lwFR9yJJEIf-LT_X64psuLkXFdbpQRJUreFE,23
|
38
|
+
h_message_bus-0.0.24.dist-info/RECORD,,
|
File without changes
|