diff --git a/src/NATSBridge.jl b/src/NATSBridge.jl index f20c50e..7a5ae51 100644 --- a/src/NATSBridge.jl +++ b/src/NATSBridge.jl @@ -56,8 +56,8 @@ struct msgPayload_v1 end # constructor -function msgPayload_v1( - id::String = ""; +function msgPayload_v1(; + id::String = "", dataname::String = "", type::String = "text", transport::String = "direct", @@ -100,8 +100,8 @@ struct msgEnvelope_v1 end # constructor -function msgEnvelope_v1( - correlationId::String = ""; +function msgEnvelope_v1(; + correlationId::String = "", msgId::String = "", timestamp::String = "", sendTo::String = "", @@ -547,7 +547,7 @@ payloads = smartreceive(msg, fileserverDownloadHandler, max_retries, base_delay, """ function smartreceive( msg::NATS.Message, - fileserverDownloadHandler::Function; + fileserverDownloadHandler::Function=_fetch_with_backoff; max_retries::Int = 5, base_delay::Int = 100, max_delay::Int = 5000 @@ -588,9 +588,9 @@ function smartreceive( # Extract URL from the payload url = String(payload_data["data"]) - # Fetch with exponential backoff using the download handler - downloaded_data = fileserverDownloadHandler(DEFAULT_FILESERVER_URL, url, max_retries, base_delay, max_delay) - + #[WORKING] Fetch with exponential backoff using the download handler + downloaded_data = fileserverDownloadHandler(json_data["data"], max_retries, base_delay, max_delay,json_data["correlationId"]) + # Deserialize based on type data_type = String(payload_data["type"]) data = _deserialize_data(downloaded_data, data_type, json_data["correlationId"]) @@ -851,4 +851,22 @@ function plik_oneshot_upload(fileServerURL::String, filepath::String) end + + + + + + + + + + + + + + + + + + end # module diff --git a/test/test_julia_julia_data_transfer.jl b/test/test_julia_julia_data_transfer.jl index 4e65d6f..464a493 100644 --- a/test/test_julia_julia_data_transfer.jl +++ b/test/test_julia_julia_data_transfer.jl @@ -81,13 +81,13 @@ function test_large_binary_receive() # For link transport, result.data is the URL log_trace("Received link transport") end - + # Verify the received data matches the original if result.envelope.type == "binary" if isa(result.data, Vector{UInt8}) file_size = length(result.data) log_trace("Received $(file_size) bytes of binary data") - + # Save received data to a test file println("metadata ", result.envelope.metadata) dataname = result.envelope.metadata["dataname"] @@ -96,7 +96,7 @@ function test_large_binary_receive() write(output_path, result.data) log_trace("Saved received data to $output_path") end - + # Verify file size original_size = length(read(FILE_PATH)) if file_size == result.envelope.metadata["content_length"]