update
This commit is contained in:
34
README.md
34
README.md
@@ -197,7 +197,7 @@ using NATSBridge
|
||||
|
||||
# Send a text message
|
||||
data = [("message", "Hello World", "text")]
|
||||
env, msg_json_str = NATSBridge.smartsend("/chat/room1", data, nats_url="nats://localhost:4222")
|
||||
env, msg_json_str = NATSBridge.smartsend("/chat/room1", data; nats_url="nats://localhost:4222")
|
||||
println("Message sent!")
|
||||
```
|
||||
|
||||
@@ -310,7 +310,7 @@ Sends data either directly via NATS or via a fileserver URL, depending on payloa
|
||||
```python
|
||||
from nats_bridge import smartsend
|
||||
|
||||
env = smartsend(
|
||||
env, msg_json_str = smartsend(
|
||||
subject, # NATS subject to publish to
|
||||
data, # List of (dataname, data, type) tuples
|
||||
nats_url="nats://localhost:4222", # NATS server URL
|
||||
@@ -333,7 +333,7 @@ env = smartsend(
|
||||
```javascript
|
||||
const { smartsend } = require('./src/NATSBridge');
|
||||
|
||||
const env = await smartsend(
|
||||
const { env, msg_json_str } = await smartsend(
|
||||
subject, // NATS subject
|
||||
data, // Array of {dataname, data, type}
|
||||
{
|
||||
@@ -359,7 +359,7 @@ const env = await smartsend(
|
||||
using NATSBridge
|
||||
|
||||
env, msg_json_str = NATSBridge.smartsend(
|
||||
subject; # NATS subject
|
||||
subject, # NATS subject
|
||||
data::AbstractArray{Tuple{String, Any, String}}; # List of (dataname, data, type)
|
||||
nats_url::String = "nats://localhost:4222",
|
||||
fileserver_url = "http://localhost:8080",
|
||||
@@ -465,7 +465,7 @@ smartsend("/topic", data)
|
||||
```javascript
|
||||
await smartsend("/topic", [
|
||||
{ dataname: "message", data: "Hello", type: "text" }
|
||||
]);
|
||||
], { isPublish: false });
|
||||
```
|
||||
|
||||
#### Julia
|
||||
@@ -488,13 +488,13 @@ smartsend("/topic", data, fileserver_url="http://localhost:8080")
|
||||
```javascript
|
||||
await smartsend("/topic", [
|
||||
{ dataname: "file", data: largeData, type: "binary" }
|
||||
], { fileserverUrl: "http://localhost:8080" });
|
||||
], { fileserverUrl: "http://localhost:8080", isPublish: false });
|
||||
```
|
||||
|
||||
#### Julia
|
||||
```julia
|
||||
data = [("file", large_data, "binary")]
|
||||
smartsend("/topic", data, fileserver_url="http://localhost:8080")
|
||||
smartsend("/topic", data; fileserver_url="http://localhost:8080")
|
||||
```
|
||||
|
||||
---
|
||||
@@ -517,14 +517,14 @@ data = [
|
||||
("large_document", large_file_data, "binary")
|
||||
]
|
||||
|
||||
smartsend("/chat/room1", data, fileserver_url="http://localhost:8080")
|
||||
env, msg_json_str = smartsend("/chat/room1", data, fileserver_url="http://localhost:8080")
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
```javascript
|
||||
const { smartsend } = require('./src/NATSBridge');
|
||||
|
||||
await smartsend("/chat/room1", [
|
||||
const { env, msg_json_str } = await smartsend("/chat/room1", [
|
||||
{ dataname: "message_text", data: "Hello!", type: "text" },
|
||||
{ dataname: "user_avatar", data: image_data, type: "image" },
|
||||
{ dataname: "large_document", data: large_file_data, type: "binary" }
|
||||
@@ -543,7 +543,7 @@ data = [
|
||||
("large_document", large_file_data, "binary")
|
||||
]
|
||||
|
||||
NATSBridge.smartsend("/chat/room1", data, fileserver_url="http://localhost:8080")
|
||||
env, msg_json_str = NATSBridge.smartsend("/chat/room1", data; fileserver_url="http://localhost:8080")
|
||||
```
|
||||
|
||||
### Example 2: Dictionary Exchange
|
||||
@@ -561,7 +561,7 @@ config = {
|
||||
}
|
||||
|
||||
data = [("config", config, "dictionary")]
|
||||
smartsend("/device/config", data)
|
||||
env, msg_json_str = smartsend("/device/config", data)
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
@@ -574,7 +574,7 @@ const config = {
|
||||
update_interval: 60
|
||||
};
|
||||
|
||||
await smartsend("/device/config", [
|
||||
const { env, msg_json_str } = await smartsend("/device/config", [
|
||||
{ dataname: "config", data: config, type: "dictionary" }
|
||||
]);
|
||||
```
|
||||
@@ -590,7 +590,7 @@ config = Dict(
|
||||
)
|
||||
|
||||
data = [("config", config, "dictionary")]
|
||||
NATSBridge.smartsend("/device/config", data)
|
||||
env, msg_json_str = NATSBridge.smartsend("/device/config", data)
|
||||
```
|
||||
|
||||
### Example 3: Table Data (Arrow IPC)
|
||||
@@ -609,7 +609,7 @@ df = pd.DataFrame({
|
||||
})
|
||||
|
||||
data = [("students", df, "table")]
|
||||
smartsend("/data/analysis", data)
|
||||
env, msg_json_str = smartsend("/data/analysis", data)
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
@@ -622,7 +622,7 @@ const tableData = [
|
||||
{ id: 3, name: "Charlie", score: 92 }
|
||||
];
|
||||
|
||||
await smartsend("/data/analysis", [
|
||||
const { env, msg_json_str } = await smartsend("/data/analysis", [
|
||||
{ dataname: "students", data: tableData, type: "table" }
|
||||
]);
|
||||
```
|
||||
@@ -639,7 +639,7 @@ df = DataFrame(
|
||||
)
|
||||
|
||||
data = [("students", df, "table")]
|
||||
NATSBridge.smartsend("/data/analysis", data)
|
||||
env, msg_json_str = NATSBridge.smartsend("/data/analysis", data)
|
||||
```
|
||||
|
||||
### Example 4: Request-Response Pattern with Envelope JSON
|
||||
@@ -738,7 +738,7 @@ using NATSBridge
|
||||
|
||||
env = NATSBridge.smartsend(
|
||||
"/device/command",
|
||||
[("command", Dict("action" => "read_sensor"), "dictionary")],
|
||||
[("command", Dict("action" => "read_sensor"), "dictionary")];
|
||||
reply_to="/device/response"
|
||||
)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user