update
This commit is contained in:
@@ -208,7 +208,7 @@ config = {
|
||||
|
||||
# Send as dictionary type
|
||||
data = [("config", config, "dictionary")]
|
||||
env = smartsend("/device/config", data, nats_url="nats://localhost:4222")
|
||||
env, msg_json_str = smartsend("/device/config", data, nats_url="nats://localhost:4222")
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
@@ -222,7 +222,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" }
|
||||
]);
|
||||
```
|
||||
@@ -239,7 +239,7 @@ config = Dict(
|
||||
)
|
||||
|
||||
data = [("config", config, "dictionary")]
|
||||
smartsend("/device/config", data)
|
||||
env, msg_json_str = smartsend("/device/config", data)
|
||||
```
|
||||
|
||||
### Example 2: Sending Binary Data (Image)
|
||||
@@ -255,7 +255,7 @@ with open("image.png", "rb") as f:
|
||||
|
||||
# Send as binary type
|
||||
data = [("user_image", image_data, "binary")]
|
||||
env = smartsend("/chat/image", data, nats_url="nats://localhost:4222")
|
||||
env, msg_json_str = smartsend("/chat/image", data, nats_url="nats://localhost:4222")
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
@@ -267,7 +267,7 @@ const { smartsend } = require('./src/NATSBridge');
|
||||
const fs = require('fs');
|
||||
const image_data = fs.readFileSync('image.png');
|
||||
|
||||
await smartsend("/chat/image", [
|
||||
const { env, msg_json_str } = await smartsend("/chat/image", [
|
||||
{ dataname: "user_image", data: image_data, type: "binary" }
|
||||
]);
|
||||
```
|
||||
@@ -281,7 +281,7 @@ using NATSBridge
|
||||
image_data = read("image.png")
|
||||
|
||||
data = [("user_image", image_data, "binary")]
|
||||
smartsend("/chat/image", data)
|
||||
env, msg_json_str = smartsend("/chat/image", data)
|
||||
```
|
||||
|
||||
### Example 3: Request-Response Pattern
|
||||
@@ -358,7 +358,7 @@ import os
|
||||
large_data = os.urandom(2_000_000) # 2MB of random data
|
||||
|
||||
# Send with file server URL
|
||||
env = smartsend(
|
||||
env, msg_json_str = smartsend(
|
||||
"/data/large",
|
||||
[("large_file", large_data, "binary")],
|
||||
nats_url="nats://localhost:4222",
|
||||
@@ -380,7 +380,7 @@ const largeData = new ArrayBuffer(2_000_000);
|
||||
const view = new Uint8Array(largeData);
|
||||
view.fill(42); // Fill with some data
|
||||
|
||||
await smartsend("/data/large", [
|
||||
const { env, msg_json_str } = await smartsend("/data/large", [
|
||||
{ dataname: "large_file", data: largeData, type: "binary" }
|
||||
], {
|
||||
fileserverUrl: "http://localhost:8080",
|
||||
@@ -396,7 +396,7 @@ using NATSBridge
|
||||
# Create large data (> 1MB)
|
||||
large_data = rand(UInt8, 2_000_000)
|
||||
|
||||
env = smartsend(
|
||||
env, msg_json_str = smartsend(
|
||||
"/data/large",
|
||||
[("large_file", large_data, "binary")],
|
||||
fileserver_url="http://localhost:8080"
|
||||
@@ -425,7 +425,7 @@ data = [
|
||||
("user_avatar", image_data, "image")
|
||||
]
|
||||
|
||||
env = smartsend("/chat/mixed", data, nats_url="nats://localhost:4222")
|
||||
env, msg_json_str = smartsend("/chat/mixed", data, nats_url="nats://localhost:4222")
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
@@ -435,7 +435,7 @@ const { smartsend } = require('./src/NATSBridge');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
await smartsend("/chat/mixed", [
|
||||
const { env, msg_json_str } = await smartsend("/chat/mixed", [
|
||||
{
|
||||
dataname: "message_text",
|
||||
data: "Hello with image!",
|
||||
@@ -461,7 +461,7 @@ data = [
|
||||
("user_avatar", image_data, "image")
|
||||
]
|
||||
|
||||
smartsend("/chat/mixed", data)
|
||||
env, msg_json_str = smartsend("/chat/mixed", data)
|
||||
```
|
||||
|
||||
### Example 6: Table Data (Arrow IPC)
|
||||
@@ -483,7 +483,7 @@ df = pd.DataFrame({
|
||||
|
||||
# Send as table type
|
||||
data = [("students", df, "table")]
|
||||
env = smartsend("/data/students", data, nats_url="nats://localhost:4222")
|
||||
env, msg_json_str = smartsend("/data/students", data, nats_url="nats://localhost:4222")
|
||||
```
|
||||
|
||||
#### Julia
|
||||
@@ -500,7 +500,7 @@ df = DataFrame(
|
||||
)
|
||||
|
||||
data = [("students", df, "table")]
|
||||
smartsend("/data/students", data)
|
||||
env, msg_json_str = smartsend("/data/students", data)
|
||||
```
|
||||
|
||||
---
|
||||
@@ -519,7 +519,7 @@ using NATSBridge
|
||||
# Send dictionary from Julia to JavaScript
|
||||
config = Dict("step_size" => 0.01, "iterations" => 1000)
|
||||
data = [("config", config, "dictionary")]
|
||||
smartsend("/analysis/config", data, nats_url="nats://localhost:4222")
|
||||
env, msg_json_str = smartsend("/analysis/config", data, nats_url="nats://localhost:4222")
|
||||
```
|
||||
|
||||
#### JavaScript Receiver
|
||||
@@ -544,7 +544,7 @@ for (const payload of envelope.payloads) {
|
||||
```javascript
|
||||
const { smartsend } = require('./src/NATSBridge');
|
||||
|
||||
await smartsend("/data/transfer", [
|
||||
const { env, msg_json_str } = await smartsend("/data/transfer", [
|
||||
{ dataname: "message", data: "Hello from JS!", type: "text" }
|
||||
]);
|
||||
```
|
||||
@@ -568,7 +568,7 @@ for dataname, data, type in envelope["payloads"]:
|
||||
from nats_bridge import smartsend
|
||||
|
||||
data = [("message", "Hello from Python!", "text")]
|
||||
smartsend("/chat/python", data)
|
||||
env, msg_json_str = smartsend("/chat/python", data)
|
||||
```
|
||||
|
||||
#### Julia Receiver
|
||||
|
||||
Reference in New Issue
Block a user