#!/usr/bin/env julia # Scenario 3: Julia-to-Julia Service Communication # Tests bi-directional communication between two Julia services using NATS using Arrow using DataFrames using JSON3 using UUIDs # Include the bridge module include("../src/julia_bridge.jl") using .BiDirectionalBridge # Configuration const SUBJECT1 = "julia_to_js" const SUBJECT2 = "js_to_julia" const RESPONSE_SUBJECT = "response" const NATS_URL = "nats://localhost:4222" # Create correlation ID for tracing correlation_id = string(uuid4()) # Julia-to-Julia Test: Large Arrow Table function test_julia_to_julia_large_table() conn = NATS.Connection(NATS_URL) try # Subscriber on SUBJECT2 to receive data from Julia sender NATS.subscribe(conn, SUBJECT2) do msg log_trace("[$(Dates.now())] Received on $SUBJECT2") # Use SmartReceive to handle the data result = SmartReceive(msg) # Check transport type if result.envelope.transport == "direct" log_trace("Received direct transport with $(length(result.data)) bytes") else # For link transport, result.data is the URL log_trace("Received link transport at $(result.data)") end # Send response back response = Dict( "status" => "Processed", "correlation_id" => result.envelope.correlation_id, "timestamp" => Dates.now() ) NATS.publish(conn, RESPONSE_SUBJECT, JSON3.stringify(response)) end # Keep listening 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 test test_julia_to_julia_large_table()