rename to smartpack n smartunpack
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Bi-Directional Data Bridge - Julia Module
|
||||
# Implements smartsend and smartreceive for message transport
|
||||
# Implements smartpack and smartunpack for message transport
|
||||
# This module provides functionality for sending and receiving data across network boundaries
|
||||
# with support for both direct payload transport and
|
||||
# URL-based transport for larger payloads.
|
||||
@@ -24,10 +24,10 @@
|
||||
#
|
||||
# API Standard:
|
||||
# ```jldoctest
|
||||
# # Input format for smartsend (always a list of tuples with type info)
|
||||
# # Input format for smartpack (always a list of tuples with type info)
|
||||
# [(dataname1, data1, type1), (dataname2, data2, type2), ...]
|
||||
#
|
||||
# # Output format for smartreceive (always returns a list of tuples)
|
||||
# # Output format for smartunpack (always returns a list of tuples)
|
||||
# [(dataname1, data1, type1), (dataname2, data2, type2), ...]
|
||||
# ```
|
||||
#
|
||||
@@ -337,7 +337,7 @@ function log_trace(correlation_id::String, message::String)
|
||||
end
|
||||
|
||||
|
||||
""" smartsend - Send data with automatic transport selection, depending on payload size
|
||||
""" smartpack - Send data with automatic transport selection, depending on payload size
|
||||
|
||||
This function intelligently routes data delivery based on payload size relative to a threshold.
|
||||
If the serialized payload is smaller than `size_threshold`, it encodes the data as Base64 and constructs a "direct" msg_payload_v1.
|
||||
@@ -392,23 +392,23 @@ using UUIDs
|
||||
|
||||
# Send a single payload (still wrapped in a list)
|
||||
data = Dict("key" => "value")
|
||||
env, msg_json = smartsend("my.subject", [("dataname1", data, "dictionary")])
|
||||
env, msg_json = smartpack("my.subject", [("dataname1", data, "dictionary")])
|
||||
|
||||
# Send multiple payloads in one message with different types
|
||||
data1 = Dict("key1" => "value1")
|
||||
data2 = rand(10_000) # Small array
|
||||
env, msg_json = smartsend("my.subject", [("dataname1", data1, "dictionary"), ("dataname2", data2, "arrowtable")])
|
||||
env, msg_json = smartpack("my.subject", [("dataname1", data1, "dictionary"), ("dataname2", data2, "arrowtable")])
|
||||
|
||||
# Send a large array using fileserver upload
|
||||
data = rand(10_000_000) # ~80 MB
|
||||
env, msg_json = smartsend("large.data", [("large_arrow_table", data, "arrowtable")])
|
||||
env, msg_json = smartpack("large.data", [("large_arrow_table", data, "arrowtable")])
|
||||
|
||||
# Send jsontable (JSON format)
|
||||
rows = [Dict("id" => 1, "name" => "Alice"), Dict("id" => 2, "name" => "Bob")]
|
||||
env, msg_json = smartsend("json.data", [("users", rows, "jsontable")])
|
||||
env, msg_json = smartpack("json.data", [("users", rows, "jsontable")])
|
||||
|
||||
# Mixed content (e.g., chat with text and image)
|
||||
env, msg_json = smartsend("chat.subject", [
|
||||
env, msg_json = smartpack("chat.subject", [
|
||||
("message_text", "Hello!", "text"),
|
||||
("user_image", image_data, "image"),
|
||||
("audio_clip", audio_data, "audio")
|
||||
@@ -419,8 +419,8 @@ env, msg_json = smartsend("chat.subject", [
|
||||
# my_transport.publish(conn, subject, env_json_str)
|
||||
```
|
||||
"""
|
||||
function smartsend(
|
||||
subject::String, # smartreceive's subject
|
||||
function smartpack(
|
||||
subject::String, # smartunpack's subject
|
||||
data::AbstractArray{Tuple{String, T1, String}, 1}; # List of (dataname, data, type) tuples. Use Tuple{String, Any, String}[] for empty payloads
|
||||
broker_url::String = DEFAULT_BROKER_URL, # Broker URL
|
||||
fileserver_url = DEFAULT_FILESERVER_URL,
|
||||
@@ -446,7 +446,7 @@ function smartsend(
|
||||
)::Tuple{msg_envelope_v1, String} where {T1<:Any}
|
||||
|
||||
# Log start of send operation
|
||||
log_trace(correlation_id, "Starting smartsend for subject: $subject")
|
||||
log_trace(correlation_id, "Starting smartpack for subject: $subject")
|
||||
|
||||
# Process each payload in the list
|
||||
payloads = msg_payload_v1[]
|
||||
@@ -772,7 +772,7 @@ end
|
||||
# end
|
||||
|
||||
|
||||
""" smartreceive - Receive and process messages
|
||||
""" smartunpack - Receive and process messages
|
||||
This function processes incoming messages, handling both direct transport
|
||||
(base64 decoded payloads) and link transport (URL-based payloads).
|
||||
It deserializes the data based on the transport type and returns the result.
|
||||
@@ -801,11 +801,11 @@ A HTTP file server is required along with its download function.
|
||||
```jldoctest
|
||||
# Receive and process message
|
||||
msg_json_str = String(msg.payload)
|
||||
env = smartreceive(msg_json_str; fileserver_download_handler=_fetch_with_backoff, max_retries=5, base_delay=100, max_delay=5000)
|
||||
env = smartunpack(msg_json_str; fileserver_download_handler=_fetch_with_backoff, max_retries=5, base_delay=100, max_delay=5000)
|
||||
# env["payloads"] = [("dataname1", data1, "type1"), ("dataname2", data2, "type2"), ...]
|
||||
```
|
||||
"""
|
||||
function smartreceive(
|
||||
function smartunpack(
|
||||
msg_json_str::String; # get it from String(nats_msg.payload)
|
||||
fileserver_download_handler::Function = _fetch_with_backoff,
|
||||
max_retries::Int = 5,
|
||||
|
||||
Reference in New Issue
Block a user