#!/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 UUIDs using JSON using Dates # Include the NATSBridge module include("../src/NATSBridge.jl") # Configuration const SUBJECT = "/NATSBridge_dict_test" const NATS_URL = "nats.yiem.cc" const FILESERVER_URL = "http://192.168.88.104: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" => string(Dates.now()) ) ) # 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.")