update
This commit is contained in:
32
README.md
32
README.md
@@ -107,17 +107,7 @@ NATSBridge enables seamless communication across Julia, JavaScript, and Python/M
|
||||
```julia
|
||||
using Pkg
|
||||
Pkg.add("NATS")
|
||||
Pkg.add("Arrow")
|
||||
Pkg.add("JSON3")
|
||||
Pkg.add("HTTP")
|
||||
Pkg.add("UUIDs")
|
||||
Pkg.add("Dates")
|
||||
```
|
||||
|
||||
Add to your `Project.toml`:
|
||||
```toml
|
||||
[NATSBridge]
|
||||
deps = ["NATS", "Arrow", "JSON3", "HTTP", "UUIDs", "Dates"]
|
||||
Pkg.add("https://git.yiem.cc/ton/NATSBridge")
|
||||
```
|
||||
|
||||
### JavaScript
|
||||
@@ -207,7 +197,7 @@ using NATSBridge
|
||||
|
||||
# Send a text message
|
||||
data = [("message", "Hello World", "text")]
|
||||
env = smartsend("/chat/room1", data, nats_url="nats://localhost:4222")
|
||||
env = NATSBridge.smartsend("/chat/room1", data, nats_url="nats://localhost:4222")
|
||||
println("Message sent!")
|
||||
```
|
||||
|
||||
@@ -242,7 +232,7 @@ for (const payload of envelope.payloads) {
|
||||
using NATSBridge
|
||||
|
||||
# Receive and process message
|
||||
envelope = smartreceive(msg, fileserverDownloadHandler)
|
||||
envelope = NATSBridge.smartreceive(msg, fileserverDownloadHandler)
|
||||
for (dataname, data, type) in envelope["payloads"]
|
||||
println("Received $dataname: $data")
|
||||
end
|
||||
@@ -307,7 +297,7 @@ const env = await smartsend(
|
||||
```julia
|
||||
using NATSBridge
|
||||
|
||||
env = smartsend(
|
||||
env = NATSBridge.smartsend(
|
||||
subject; # NATS subject
|
||||
data::AbstractArray{Tuple{String, Any, String}}; # List of (dataname, data, type)
|
||||
nats_url::String = "nats://localhost:4222",
|
||||
@@ -365,7 +355,7 @@ const envelope = await smartreceive(
|
||||
```julia
|
||||
using NATSBridge
|
||||
|
||||
envelope = smartreceive(
|
||||
envelope = NATSBridge.smartreceive(
|
||||
msg::NATS.Msg;
|
||||
fileserverDownloadHandler::Function = _fetch_with_backoff,
|
||||
max_retries::Int = 5,
|
||||
@@ -485,7 +475,7 @@ data = [
|
||||
("large_document", large_file_data, "binary")
|
||||
]
|
||||
|
||||
smartsend("/chat/room1", data, fileserver_url="http://localhost:8080")
|
||||
NATSBridge.smartsend("/chat/room1", data, fileserver_url="http://localhost:8080")
|
||||
```
|
||||
|
||||
### Example 2: Dictionary Exchange
|
||||
@@ -532,7 +522,7 @@ config = Dict(
|
||||
)
|
||||
|
||||
data = [("config", config, "dictionary")]
|
||||
smartsend("/device/config", data)
|
||||
NATSBridge.smartsend("/device/config", data)
|
||||
```
|
||||
|
||||
### Example 3: Table Data (Arrow IPC)
|
||||
@@ -581,7 +571,7 @@ df = DataFrame(
|
||||
)
|
||||
|
||||
data = [("students", df, "table")]
|
||||
smartsend("/data/analysis", data)
|
||||
NATSBridge.smartsend("/data/analysis", data)
|
||||
```
|
||||
|
||||
### Example 4: Request-Response Pattern
|
||||
@@ -640,7 +630,7 @@ for (const payload of envelope.payloads) {
|
||||
```julia
|
||||
using NATSBridge
|
||||
|
||||
env = smartsend(
|
||||
env = NATSBridge.smartsend(
|
||||
"/device/command",
|
||||
[("command", Dict("action" => "read_sensor"), "dictionary")],
|
||||
reply_to="/device/response"
|
||||
@@ -651,7 +641,7 @@ env = smartsend(
|
||||
```julia
|
||||
using NATSBridge
|
||||
|
||||
envelope = smartreceive(msg, fileserverDownloadHandler)
|
||||
envelope = NATSBridge.smartreceive(msg, fileserverDownloadHandler)
|
||||
for (dataname, data, type) in envelope["payloads"]
|
||||
if dataname == "command" && data["action"] == "read_sensor"
|
||||
response = Dict("sensor_id" => "sensor-001", "value" => 42.5)
|
||||
@@ -699,7 +689,7 @@ for (const payload of envelope.payloads) {
|
||||
```julia
|
||||
using NATSBridge
|
||||
|
||||
envelope = smartreceive(msg, fileserverDownloadHandler)
|
||||
envelope = NATSBridge.smartreceive(msg, fileserverDownloadHandler)
|
||||
for (dataname, data, type) in envelope["payloads"]
|
||||
if dataname == "temperature"
|
||||
println("Temperature: $data")
|
||||
|
||||
Reference in New Issue
Block a user