add test
This commit is contained in:
90
test/julia_to_julia_dict_sender.jl
Normal file
90
test/julia_to_julia_dict_sender.jl
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env julia
|
||||
# Test script for dictionary transfer from Julia serviceA to Julia serviceB
|
||||
# Demonstrates the "Command & Control" scenario (small dictionary) using NATSBridge
|
||||
#
|
||||
# This is serviceA - the sender that sends a dummy dictionary to serviceB
|
||||
|
||||
using NATSBridge
|
||||
using UUIDs
|
||||
using JSON
|
||||
|
||||
# Include the NATSBridge module
|
||||
include("src/NATSBridge.jl")
|
||||
|
||||
# Configuration
|
||||
const SUBJECT = "/NATSBridge_dict_test"
|
||||
const NATS_URL = "nats://localhost:4222"
|
||||
const FILESERVER_URL = "http://localhost:8080"
|
||||
|
||||
# Create correlation ID for tracing
|
||||
correlation_id = string(uuid4())
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ #
|
||||
# dictionary sender #
|
||||
# ------------------------------------------------------------------------------------------------ #
|
||||
|
||||
|
||||
# Helper: Log with correlation ID
|
||||
function log_trace(message)
|
||||
timestamp = Dates.now()
|
||||
println("[$timestamp] [Correlation: $correlation_id] $message")
|
||||
end
|
||||
|
||||
|
||||
# Sender: Send a dummy dictionary to serviceB
|
||||
function send_dictionary()
|
||||
# Create a dummy dictionary to send
|
||||
dummy_dict = Dict(
|
||||
"command" => "start_simulation",
|
||||
"simulation_id" => string(uuid4()),
|
||||
"duration_seconds" => 60,
|
||||
"parameters" => Dict(
|
||||
"temperature" => 25.5,
|
||||
"pressure" => 101.3,
|
||||
"active" => true,
|
||||
"tags" => ["test", "simulation", "julia_to_julia"]
|
||||
),
|
||||
"metadata" => Dict(
|
||||
"sender" => "serviceA",
|
||||
"timestamp" => Dates.now().iso8601
|
||||
)
|
||||
)
|
||||
|
||||
# Send the dictionary using smartsend with type="dictionary"
|
||||
# API: smartsend(subject, [(dataname, data, type), ...]; keywords...)
|
||||
env = NATSBridge.smartsend(
|
||||
SUBJECT,
|
||||
[("dummy_dict", dummy_dict, "dictionary")], # List of (dataname, data, type) tuples
|
||||
nats_url = NATS_URL,
|
||||
fileserver_url = FILESERVER_URL,
|
||||
size_threshold = 1_000_000, # 1MB threshold - dictionary will use direct transport
|
||||
correlation_id = correlation_id,
|
||||
msg_purpose = "chat",
|
||||
sender_name = "serviceA",
|
||||
receiver_name = "serviceB",
|
||||
reply_to = "",
|
||||
reply_to_msg_id = ""
|
||||
)
|
||||
|
||||
log_trace("Sent dictionary via $(env.payloads[1].transport) transport")
|
||||
log_trace("Payload type: $(env.payloads[1].type)")
|
||||
log_trace("Envelope correlationId: $(env.correlationId)")
|
||||
|
||||
# Display the sent dictionary
|
||||
println("\nSent dictionary content:")
|
||||
println(JSON.json(dummy_dict, 2))
|
||||
end
|
||||
|
||||
|
||||
# Run the test
|
||||
println("Starting dictionary transfer test...")
|
||||
println("Correlation ID: $correlation_id")
|
||||
println("Subject: $SUBJECT")
|
||||
println("NATS URL: $NATS_URL")
|
||||
|
||||
# Run sender
|
||||
println("\n--- Sending dictionary ---")
|
||||
send_dictionary()
|
||||
|
||||
println("\nTest completed.")
|
||||
Reference in New Issue
Block a user