#!/usr/bin/env julia # Scenario 1: Command & Control (Small JSON) # Tests small JSON payloads (< 1MB) sent directly via NATS using NATS using JSON3 using UUIDs # Include the bridge module include("../src/julia_bridge.jl") using .BiDirectionalBridge # Configuration const CONTROL_SUBJECT = "control" const RESPONSE_SUBJECT = "control_response" const NATS_URL = "nats://localhost:4222" # Create correlation ID for tracing correlation_id = string(uuid4()) # Receiver: Listen for control commands function start_control_listener() conn = NATS.Connection(NATS_URL) try NATS.subscribe(conn, CONTROL_SUBJECT) do msg log_trace(msg.data) # Parse the envelope env = MessageEnvelope(String(msg.data)) # Parse JSON payload config = JSON3.read(env.payload) # Execute simulation with parameters step_size = config.step_size iterations = config.iterations # Simulate processing sleep(0.1) # Simulate some work # Send acknowledgment response = Dict( "status" => "Running", "correlation_id" => env.correlation_id, "step_size" => step_size, "iterations" => iterations ) NATS.publish(conn, RESPONSE_SUBJECT, JSON3.stringify(response)) log_trace("Sent response: $(JSON3.stringify(response))") end # Keep listening for 5 seconds sleep(5) finally NATS.close(conn) end end # Helper: Log with correlation ID function log_trace(message) timestamp = Dates.now() println("[$timestamp] [Correlation: $correlation_id] $message") end # Run the listener start_control_listener()