diff --git a/README.md b/README.md index cb94002..ac54572 100644 --- a/README.md +++ b/README.md @@ -109,11 +109,10 @@ msghandler enables seamless communication across multiple platforms through NATS ```julia using msghandler, NATS - -data = [("message", "Hello World", "text")] -env, env_json_str = smartpack("/chat/room1", data; broker_url="nats://localhost:4222") +data = [("test_message", "Hello World", "text")] # payloads to be send format is [(dataname, data, type), ...] tuples. +envelope, envelope_json_str = smartpack("test.topic", data; broker_url="nats.yiem.cc") conn = NATS.connect(broker_url) # Create NATS connection -NATS.publish(conn, subject, message) # Publish message to NATS +NATS.publish(conn, "test.topic", envelope_json_str) # Publish message to NATS NATS.drain(conn) ``` @@ -174,6 +173,28 @@ env, env_json_str = smartpack( print("Message sent!") ``` +### Receive Your First Message + +#### Julia + +```julia +using msghandler, NATS + +conn = NATS.connect("nats.yiem.cc") +NATS.subscribe(conn, "test.topic") do msg + log_trace("Received message on $(msg.subject)") + + # Use NATSBridge.smartreceive to handle the data + # API: smartreceive(msg, download_handler; max_retries, base_delay, max_delay) + envelope = msghandler.smartunpack( + msg; + max_retries = 5, + base_delay = 100, + max_delay = 5000 + ) +end +``` + --- ## API Reference diff --git a/src/msghandler.jl b/src/msghandler.jl index 87fcc2f..59210c4 100644 --- a/src/msghandler.jl +++ b/src/msghandler.jl @@ -421,7 +421,7 @@ env, msg_json = smartpack("chat.subject", [ """ function smartpack( subject::String, # smartunpack's subject - data::AbstractArray{Tuple{String, T1, String}, 1}; # List of (dataname, data, type) tuples. Use Tuple{String, Any, String}[] for empty payloads + data::AbstractArray{Tuple{String, T1, String}, 1}; # List of (dataname, data, type) tuples. Use data = Tuple{String, Any, String}[] for empty payloads broker_url::String = DEFAULT_BROKER_URL, # Broker URL fileserver_url = DEFAULT_FILESERVER_URL, fileserver_upload_handler::Function = plik_oneshot_upload, # a function to handle uploading data to specific HTTP fileserver