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