97 lines
3.1 KiB
Julia
97 lines
3.1 KiB
Julia
#!/usr/bin/env julia
|
|
# Test script for DataFrame transfer from Julia serviceA to Julia serviceB
|
|
# Demonstrates the "Selection" scenario (small Arrow table) using NATSBridge
|
|
#
|
|
# This is serviceA - the sender that sends a dummy DataFrame to serviceB
|
|
|
|
using NATSBridge
|
|
using UUIDs
|
|
using DataFrames
|
|
using JSON
|
|
using Dates
|
|
|
|
# Include the NATSBridge module
|
|
include("src/NATSBridge.jl")
|
|
|
|
# Configuration
|
|
const SUBJECT = "/NATSBridge_table_test"
|
|
const NATS_URL = "nats://localhost:4222"
|
|
const FILESERVER_URL = "http://localhost:8080"
|
|
|
|
# Create correlation ID for tracing
|
|
correlation_id = string(uuid4())
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------ #
|
|
# DataFrame sender #
|
|
# ------------------------------------------------------------------------------------------------ #
|
|
|
|
|
|
# Helper: Log with correlation ID
|
|
function log_trace(message)
|
|
timestamp = Dates.now()
|
|
println("[$timestamp] [Correlation: $correlation_id] $message")
|
|
end
|
|
|
|
|
|
# Sender: Send a dummy DataFrame to serviceB
|
|
function send_dataframe()
|
|
# Create a dummy DataFrame (table) to send
|
|
# This simulates a selection scenario where Julia server generates options for user selection
|
|
dummy_df = DataFrame(
|
|
id = 1:10,
|
|
name = ["Option A", "Option B", "Option C", "Option D", "Option E",
|
|
"Option F", "Option G", "Option H", "Option I", "Option J"],
|
|
score = [95, 88, 92, 78, 85, 90, 87, 93, 89, 91],
|
|
category = ["A", "B", "A", "C", "B", "A", "C", "A", "B", "C"],
|
|
active = [true, true, false, true, true, false, true, true, true, false]
|
|
)
|
|
|
|
# Calculate approximate size
|
|
df_size = sizeof(dummy_df)
|
|
log_trace("DataFrame size: $(df_size / 1024) KB")
|
|
|
|
# Check if DataFrame is small enough for direct transport (< 1MB)
|
|
if df_size < 1_000_000
|
|
log_trace("Using direct transport (size < 1MB)")
|
|
else
|
|
log_trace("Using link transport (size >= 1MB)")
|
|
end
|
|
|
|
# Send the DataFrame using smartsend with type="table"
|
|
# API: smartsend(subject, [(dataname, data, type), ...]; keywords...)
|
|
env = NATSBridge.smartsend(
|
|
SUBJECT,
|
|
[("selection_table", dummy_df, "table")], # List of (dataname, data, type) tuples
|
|
nats_url = NATS_URL,
|
|
fileserver_url = FILESERVER_URL,
|
|
size_threshold = 1_000_000, # 1MB threshold
|
|
correlation_id = correlation_id,
|
|
msg_purpose = "chat",
|
|
sender_name = "serviceA",
|
|
receiver_name = "serviceB",
|
|
reply_to = "",
|
|
reply_to_msg_id = ""
|
|
)
|
|
|
|
log_trace("Sent DataFrame via $(env.payloads[1].transport) transport")
|
|
log_trace("Payload type: $(env.payloads[1].type)")
|
|
log_trace("Envelope correlationId: $(env.correlationId)")
|
|
|
|
# Display the sent DataFrame
|
|
println("\nSent DataFrame content:")
|
|
println(dummy_df)
|
|
end
|
|
|
|
|
|
# Run the test
|
|
println("Starting DataFrame transfer test...")
|
|
println("Correlation ID: $correlation_id")
|
|
println("Subject: $SUBJECT")
|
|
println("NATS URL: $NATS_URL")
|
|
|
|
# Run sender
|
|
println("\n--- Sending DataFrame ---")
|
|
send_dataframe()
|
|
|
|
println("\nTest completed.") |