v1.1.0-fix_JS_version #2
53
README.md
53
README.md
@@ -328,59 +328,6 @@ for (const [dataname, data, type] of envelope.payloads) {
|
||||
mkdir -p /tmp/fileserver
|
||||
python3 -m http.server 8080 --directory /tmp/fileserver
|
||||
```
|
||||
|
||||
### Send Your First Message
|
||||
|
||||
```julia
|
||||
# Julia
|
||||
using msghandler, NATS
|
||||
|
||||
# Data format: [(dataname, data, type), ...]
|
||||
payload_1 = ("test_message", "Hello World", "text")
|
||||
file_path_large_image = "./test/large_image.png"
|
||||
file_data_large_image = read(file_path_large_image)
|
||||
filename_large_image = basename(file_path_large_image)
|
||||
payload_2 = (filename_large_image, file_data_large_image, "binary")
|
||||
|
||||
payloads = [payload_1, payload_2] # List of tuples
|
||||
|
||||
# Step 1: Create the message envelope (transport-agnostic)
|
||||
envelope, envelope_json_str = msghandler.smartpack("test.topic",
|
||||
payloads;
|
||||
broker_url="nats.yiem.cc",
|
||||
fileserver_url="http://192.168.88.104:8080")
|
||||
|
||||
# Step 2: Send via your chosen transport (NATS in this example)
|
||||
conn = NATS.connect("nats.yiem.cc")
|
||||
NATS.publish(conn, "test.topic", envelope_json_str; reply_to="test.replytopic")
|
||||
NATS.drain(conn)
|
||||
|
||||
# OR using request-reply pattern
|
||||
reply = NATS.request(conn, "test.topic", envelope_json_str, timeout=10)
|
||||
```
|
||||
|
||||
### Receive Your First Message
|
||||
|
||||
```julia
|
||||
# Julia
|
||||
using msghandler, NATS
|
||||
|
||||
conn = NATS.connect("nats.yiem.cc")
|
||||
NATS.subscribe(conn, "test.topic") do msg
|
||||
println("Received message on $(msg.subject)")
|
||||
envelope_json_str = String(msg.payload)
|
||||
|
||||
# Step 2: Unpack the envelope (transport-agnostic)
|
||||
envelope = msghandler.smartunpack(
|
||||
envelope_json_str;
|
||||
max_retries = 5,
|
||||
base_delay = 100,
|
||||
max_delay = 5000
|
||||
)
|
||||
println(envelope.payloads[1])
|
||||
end
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## API Reference
|
||||
|
||||
Reference in New Issue
Block a user