update
This commit is contained in:
@@ -437,7 +437,7 @@ def plik_oneshot_upload(file_server_url, filename, data):
|
||||
def smartsend(subject, data, nats_url=DEFAULT_NATS_URL, fileserver_url=DEFAULT_FILESERVER_URL,
|
||||
fileserver_upload_handler=plik_oneshot_upload, size_threshold=DEFAULT_SIZE_THRESHOLD,
|
||||
correlation_id=None, msg_purpose="chat", sender_name="NATSBridge",
|
||||
receiver_name="", receiver_id="", reply_to="", reply_to_msg_id=""):
|
||||
receiver_name="", receiver_id="", reply_to="", reply_to_msg_id="", is_publish=True):
|
||||
"""Send data either directly via NATS or via a fileserver URL, depending on payload size.
|
||||
|
||||
This function intelligently routes data delivery based on payload size relative to a threshold.
|
||||
@@ -459,9 +459,12 @@ def smartsend(subject, data, nats_url=DEFAULT_NATS_URL, fileserver_url=DEFAULT_F
|
||||
receiver_id: UUID of the receiver
|
||||
reply_to: Topic to reply to
|
||||
reply_to_msg_id: Message ID this message is replying to
|
||||
is_publish: Whether to automatically publish the message to NATS (default: True)
|
||||
|
||||
Returns:
|
||||
MessageEnvelope: The envelope object for tracking
|
||||
tuple: (env, msg_json_str) where:
|
||||
- env: MessageEnvelope object with all metadata and payloads
|
||||
- msg_json_str: JSON string representation of the envelope for publishing
|
||||
"""
|
||||
# Generate correlation ID if not provided
|
||||
cid = correlation_id if correlation_id else str(uuid.uuid4())
|
||||
@@ -549,13 +552,15 @@ def smartsend(subject, data, nats_url=DEFAULT_NATS_URL, fileserver_url=DEFAULT_F
|
||||
|
||||
msg_json = env.to_json()
|
||||
|
||||
# Publish to NATS
|
||||
nats_conn = NATSConnection(nats_url)
|
||||
nats_conn.connect()
|
||||
nats_conn.publish(subject, msg_json)
|
||||
nats_conn.close()
|
||||
# Publish to NATS if is_publish is True
|
||||
if is_publish:
|
||||
nats_conn = NATSConnection(nats_url)
|
||||
nats_conn.connect()
|
||||
nats_conn.publish(subject, msg_json)
|
||||
nats_conn.close()
|
||||
|
||||
return env
|
||||
# Return tuple of (envelope, json_string) for both direct and link transport
|
||||
return (env, msg_json)
|
||||
|
||||
|
||||
def smartreceive(msg, fileserver_download_handler=_fetch_with_backoff, max_retries=5,
|
||||
|
||||
Reference in New Issue
Block a user