2 Commits

Author SHA1 Message Date
7205cc1ea3 update 2026-03-06 08:36:51 +07:00
aa7cdbd36f update 2026-03-06 08:19:15 +07:00
32 changed files with 344 additions and 119 deletions

View File

@@ -47,9 +47,9 @@ NATSBridge enables seamless communication across multiple platforms through NATS
| Platform | Implementation | Features | | Platform | Implementation | Features |
|----------|----------------|----------| |----------|----------------|----------|
| **Julia** | [`src/NATSBridge.jl`](src/NATSBridge.jl) | Full feature set, Arrow IPC, multiple dispatch | | **Julia** | [`src/NATSBridge.jl`](src/NATSBridge.jl) | Full feature set, Arrow IPC, multiple dispatch |
| **JavaScript** | [`src/natbridge.js`](src/natbridge.js) | Node.js & browser, async/await | | **JavaScript** | [`src/natsbridge.js`](src/natsbridge.js) | Node.js & browser, async/await |
| **Python** | [`src/natbridge.py`](src/natbridge.py) | Desktop Python, asyncio, type hints | | **Python** | [`src/natsbridge.py`](src/natsbridge.py) | Desktop Python, asyncio, type hints |
| **MicroPython** | [`src/natbridge_mpy.py`](src/natbridge_mpy.py) | Memory-constrained, synchronous API | | **MicroPython** | [`src/natsbridge_mpy.py`](src/natsbridge_mpy.py) | Memory-constrained, synchronous API |
### Platform Comparison ### Platform Comparison
@@ -332,7 +332,7 @@ env, env_json_str = NATSBridge.smartsend(
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
subject, subject,
@@ -361,7 +361,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
env, env_json_str = await NATSBridge.smartsend( env, env_json_str = await NATSBridge.smartsend(
subject: str, subject: str,
@@ -388,7 +388,7 @@ env, env_json_str = await NATSBridge.smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Limited to direct transport (< 100KB threshold) # Limited to direct transport (< 100KB threshold)
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(
@@ -551,7 +551,7 @@ env, env_json_str = NATSBridge.smartsend("/chat/room1", data; fileserver_url="ht
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const data = [ const data = [
["message_text", "Hello!", "text"], ["message_text", "Hello!", "text"],
@@ -569,7 +569,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
data = [ data = [
("message_text", "Hello!", "text"), ("message_text", "Hello!", "text"),
@@ -606,7 +606,7 @@ env, env_json_str = NATSBridge.smartsend("/device/config", data)
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const config = { const config = {
wifi_ssid: "MyNetwork", wifi_ssid: "MyNetwork",
@@ -623,7 +623,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
config = { config = {
"wifi_ssid": "MyNetwork", "wifi_ssid": "MyNetwork",
@@ -658,7 +658,7 @@ env, env_json_str = NATSBridge.smartsend("/data/analysis", data)
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const df = [ const df = [
{ id: 1, name: "Alice", score: 95 }, { id: 1, name: "Alice", score: 95 },
@@ -675,7 +675,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
import pandas as pd import pandas as pd
df = pd.DataFrame({ df = pd.DataFrame({
@@ -735,7 +735,7 @@ end
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
// Requester // Requester
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
@@ -748,7 +748,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
```javascript ```javascript
// Responder // Responder
const nats = require('nats'); const nats = require('nats');
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
async function testResponder() { async function testResponder() {
const conn = await nats.connect('nats://localhost:4222'); const conn = await nats.connect('nats://localhost:4222');
@@ -782,7 +782,7 @@ async function testResponder() {
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Requester # Requester
env, env_json_str = await NATSBridge.smartsend( env, env_json_str = await NATSBridge.smartsend(
@@ -795,7 +795,7 @@ env, env_json_str = await NATSBridge.smartsend(
```python ```python
# Responder # Responder
from natbridge import NATSBridge from natsbridge import NATSBridge
import asyncio import asyncio
import nats import nats

View File

@@ -82,7 +82,7 @@ env = smartreceive(msg; fileserver_download_handler=_fetch_with_backoff)
**JavaScript:** **JavaScript:**
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
// Send // Send
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
@@ -104,7 +104,7 @@ const env = await NATSBridge.smartreceive(msg, {
**Python:** **Python:**
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Send # Send
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(
@@ -124,7 +124,7 @@ env = NATSBridge.smartreceive(
**MicroPython:** **MicroPython:**
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Send (limited to direct transport due to memory constraints) # Send (limited to direct transport due to memory constraints)
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(

View File

@@ -16,9 +16,9 @@ This document describes the implementation of the high-performance, bi-direction
| Language | Implementation File | Description | | Language | Implementation File | Description |
|----------|---------------------|-------------| |----------|---------------------|-------------|
| **Julia** | [`src/NATSBridge.jl`](../src/NATSBridge.jl) | Full Julia implementation with Arrow IPC support | | **Julia** | [`src/NATSBridge.jl`](../src/NATSBridge.jl) | Full Julia implementation with Arrow IPC support |
| **JavaScript** | `src/natbridge.js` | Node.js/browser implementation | | **JavaScript** | `src/natsbridge.js` | Node.js/browser implementation |
| **Python** | `src/natbridge.py` | Desktop Python implementation | | **Python** | `src/natsbridge.py` | Desktop Python implementation |
| **MicroPython** | `src/natbridge_mpy.py` | MicroPython implementation (limited features) | | **MicroPython** | `src/natsbridge_mpy.py` | MicroPython implementation (limited features) |
--- ---
@@ -228,7 +228,7 @@ end
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
// Single payload // Single payload
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
@@ -275,7 +275,7 @@ for (const [dataname, data, type] of env.payloads) {
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Single payload # Single payload
env, env_json_str = await NATSBridge.smartsend( env, env_json_str = await NATSBridge.smartsend(
@@ -317,7 +317,7 @@ for dataname, data, type_ in env["payloads"]:
#### MicroPython #### MicroPython
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Limited to text and binary (no tables due to memory constraints) # Limited to text and binary (no tables due to memory constraints)
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(
@@ -929,7 +929,7 @@ end
#### Module Structure #### Module Structure
```javascript ```javascript
// natbridge.js // natsbridge.js
const nats = require('nats'); const nats = require('nats');
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require('uuid');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
@@ -1272,7 +1272,7 @@ async function plikOneshotUpload(file_server_url, dataname, data) {
#### Module Structure #### Module Structure
```python ```python
# natbridge.py # natsbridge.py
import asyncio import asyncio
import base64 import base64
import json import json
@@ -1690,7 +1690,7 @@ MicroPython has significant constraints compared to desktop implementations:
### MicroPython Module Structure ### MicroPython Module Structure
```python ```python
# natbridge_mpy.py (MicroPython) # natsbridge_mpy.py (MicroPython)
import network import network
import time import time
import json import json

View File

@@ -134,7 +134,7 @@ env, env_json_str = smartsend("/chat/room1", data, broker_url="nats://localhost:
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Send a text message // Send a text message
const data = [["message", "Hello World", "text"]]; const data = [["message", "Hello World", "text"]];
@@ -158,7 +158,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Send a text message # Send a text message
data = [("message", "Hello World", "text")] data = [("message", "Hello World", "text")]
@@ -185,7 +185,7 @@ env, env_json_str = await smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -218,7 +218,7 @@ end
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Receive and process message // Receive and process message
const env = await NATSBridge.smartreceive(msg, { const env = await NATSBridge.smartreceive(msg, {
@@ -233,7 +233,7 @@ for (const [dataname, data, type] of env.payloads) {
#### Python #### Python
```python ```python
from natbridge import smartreceive, fetch_with_backoff from natsbridge import smartreceive, fetch_with_backoff
# Receive and process message # Receive and process message
env = await smartreceive( env = await smartreceive(
@@ -269,7 +269,7 @@ env, env_json_str = smartsend("/device/config", data, broker_url="nats://localho
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const config = { const config = {
wifi_ssid: "MyNetwork", wifi_ssid: "MyNetwork",
@@ -288,7 +288,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
config = { config = {
"wifi_ssid": "MyNetwork", "wifi_ssid": "MyNetwork",
@@ -307,7 +307,7 @@ env, env_json_str = await smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -342,7 +342,7 @@ env, env_json_str = smartsend("/chat/image", data, broker_url="nats://localhost:
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
// Read image file // Read image file
@@ -359,7 +359,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Read image file # Read image file
with open("image.png", "rb") as f: with open("image.png", "rb") as f:
@@ -376,7 +376,7 @@ env, env_json_str = await smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -413,7 +413,7 @@ env, env_json_str = smartsend(
#### JavaScript (Requester) #### JavaScript (Requester)
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Send command with reply-to // Send command with reply-to
const data = [["command", { action: "read_sensor" }, "dictionary"]]; const data = [["command", { action: "read_sensor" }, "dictionary"]];
@@ -431,7 +431,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python (Requester) #### Python (Requester)
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Send command with reply-to # Send command with reply-to
data = [("command", {"action": "read_sensor"}, "dictionary")] data = [("command", {"action": "read_sensor"}, "dictionary")]
@@ -506,7 +506,7 @@ println("File uploaded to: $(env.payloads[1].data)")
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Create large data (> 1MB) // Create large data (> 1MB)
const large_data = Buffer.alloc(2_000_000); const large_data = Buffer.alloc(2_000_000);
@@ -530,7 +530,7 @@ console.log("File uploaded to:", env.payloads[0].data);
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Create large data (> 1MB) # Create large data (> 1MB)
import os import os
@@ -552,7 +552,7 @@ print(f"File uploaded to: {env['payloads'][0]['data']}")
MicroPython enforces a hard limit of 50KB per payload: MicroPython enforces a hard limit of 50KB per payload:
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -590,7 +590,7 @@ env, env_json_str = smartsend("/chat/mixed", data, broker_url="nats://localhost:
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
const image_data = fs.readFileSync('avatar.png'); const image_data = fs.readFileSync('avatar.png');
@@ -610,7 +610,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
with open("avatar.png", "rb") as f: with open("avatar.png", "rb") as f:
image_data = f.read() image_data = f.read()
@@ -652,7 +652,7 @@ env, env_json_str = smartsend("/data/students", data, broker_url="nats://localho
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Create table data (array of objects) // Create table data (array of objects)
const table_data = [ const table_data = [
@@ -672,7 +672,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
import pandas as pd import pandas as pd
# Create DataFrame # Create DataFrame

View File

@@ -177,7 +177,7 @@ end
```javascript ```javascript
// src/chat_ui.js // src/chat_ui.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
class ChatUI { class ChatUI {
constructor() { constructor() {
@@ -333,7 +333,7 @@ end
```javascript ```javascript
// src/chat_handler.js // src/chat_handler.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const nats = require('nats'); const nats = require('nats');
class ChatHandler { class ChatHandler {
@@ -393,7 +393,7 @@ module.exports = ChatHandler;
# src/chat_handler.py # src/chat_handler.py
import asyncio import asyncio
from typing import Optional from typing import Optional
from natbridge import smartreceive, fetch_with_backoff from natsbridge import smartreceive, fetch_with_backoff
class ChatHandler: class ChatHandler:
def __init__(self, nats_connection): def __init__(self, nats_connection):
@@ -526,7 +526,7 @@ end
```javascript ```javascript
// src/file_upload_service.js // src/file_upload_service.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
class FileUploadService { class FileUploadService {
@@ -580,7 +580,7 @@ module.exports = FileUploadService;
```python ```python
# src/file_upload_service.py # src/file_upload_service.py
from natbridge import smartsend from natsbridge import smartsend
import os import os
class FileUploadService: class FileUploadService:
@@ -659,7 +659,7 @@ end
```javascript ```javascript
// src/file_download_service.js // src/file_download_service.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
class FileDownloadService { class FileDownloadService {
@@ -690,7 +690,7 @@ module.exports = FileDownloadService;
```python ```python
# src/file_download_service.py # src/file_download_service.py
from natbridge import smartreceive, fetch_with_backoff from natsbridge import smartreceive, fetch_with_backoff
import os import os
class FileDownloadService: class FileDownloadService:
@@ -832,7 +832,7 @@ end
```javascript ```javascript
// src/sensor_data.js // src/sensor_data.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
class SensorReading { class SensorReading {
constructor(sensorId, value, unit, metadata = {}) { constructor(sensorId, value, unit, metadata = {}) {
@@ -985,7 +985,7 @@ end
```javascript ```javascript
// src/sensor_sender.js // src/sensor_sender.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const { SensorReading, SensorBatch } = require('./sensor_data.js'); const { SensorReading, SensorBatch } = require('./sensor_data.js');
class SensorSender { class SensorSender {
@@ -1069,7 +1069,7 @@ module.exports = SensorSender;
```python ```python
# src/sensor_sender.py # src/sensor_sender.py
from natbridge import smartsend from natsbridge import smartsend
from sensor_data import SensorReading, SensorBatch from sensor_data import SensorReading, SensorBatch
class SensorSender: class SensorSender:
@@ -1282,7 +1282,7 @@ end
# Cache file server responses # Cache file server responses
import asyncio import asyncio
import threading import threading
from natbridge import fetch_with_backoff from natsbridge import fetch_with_backoff
file_cache = {} file_cache = {}
cache_lock = threading.Lock() cache_lock = threading.Lock()

View File

@@ -6,7 +6,7 @@ This module provides functionality for sending and receiving data across network
using NATS as the message bus, with support for both direct payload transport and using NATS as the message bus, with support for both direct payload transport and
URL-based transport for larger payloads. URL-based transport for larger payloads.
@package natbridge @package natsbridge
""" """
import asyncio import asyncio

View File

@@ -3,7 +3,8 @@
* Tests the smartreceive function with binary/image/audio/video payloads * Tests the smartreceive function with binary/image/audio/video payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
@@ -18,15 +19,15 @@ async function runTest() {
const genericBinary = Buffer.from([0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE]); const genericBinary = Buffer.from([0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE]);
const testData = { const testData = {
correlation_id: 'js-binary-receiver-' + Date.now(), correlation_id: 'js-binary-receiver-' + crypto.randomUUID(),
msg_id: 'msg-' + Date.now(), msg_id: 'msg-' + crypto.randomUUID(),
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
send_to: '/test/binary', send_to: '/test/binary',
msg_purpose: 'test', msg_purpose: 'test',
sender_name: 'js-binary-test', sender_name: 'js-binary-test',
sender_id: 'sender-' + Date.now(), sender_id: 'sender-' + crypto.randomUUID(),
receiver_name: 'js-receiver', receiver_name: 'js-receiver',
receiver_id: 'receiver-' + Date.now(), receiver_id: 'receiver-' + crypto.randomUUID(),
reply_to: '', reply_to: '',
reply_to_msg_id: '', reply_to_msg_id: '',
broker_url: TEST_BROKER_URL, broker_url: TEST_BROKER_URL,

View File

@@ -3,7 +3,8 @@
* Tests the smartsend function with binary/image/audio/video payloads * Tests the smartsend function with binary/image/audio/video payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_SUBJECT = '/test/binary'; const TEST_SUBJECT = '/test/binary';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
async function runTest() { async function runTest() {
console.log('=== JavaScript Binary Sender Test ===\n'); console.log('=== JavaScript Binary Sender Test ===\n');
const correlationId = NATSBridge.uuidv4(); const correlationId = crypto.randomUUID();
console.log(`Correlation ID: ${correlationId}`); console.log(`Correlation ID: ${correlationId}`);
console.log(`Subject: ${TEST_SUBJECT}`); console.log(`Subject: ${TEST_SUBJECT}`);
console.log(`Broker URL: ${TEST_BROKER_URL}\n`); console.log(`Broker URL: ${TEST_BROKER_URL}\n`);

View File

@@ -3,7 +3,8 @@
* Tests the smartreceive function with dictionary payloads * Tests the smartreceive function with dictionary payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
@@ -18,15 +19,15 @@ async function runTest() {
const mixedDict = { string: 'text', number: 123, boolean: true, null_val: null }; const mixedDict = { string: 'text', number: 123, boolean: true, null_val: null };
const testData = { const testData = {
correlation_id: 'test-receiver-dict-' + Date.now(), correlation_id: 'test-receiver-dict-' + crypto.randomUUID(),
msg_id: 'msg-' + Date.now(), msg_id: 'msg-' + crypto.randomUUID(),
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
send_to: '/test/dictionary', send_to: '/test/dictionary',
msg_purpose: 'test', msg_purpose: 'test',
sender_name: 'js-dict-test', sender_name: 'js-dict-test',
sender_id: 'sender-' + Date.now(), sender_id: 'sender-' + crypto.randomUUID(),
receiver_name: 'js-receiver', receiver_name: 'js-receiver',
receiver_id: 'receiver-' + Date.now(), receiver_id: 'receiver-' + crypto.randomUUID(),
reply_to: '', reply_to: '',
reply_to_msg_id: '', reply_to_msg_id: '',
broker_url: TEST_BROKER_URL, broker_url: TEST_BROKER_URL,
@@ -161,15 +162,15 @@ async function runTest() {
// Test round-trip with receive // Test round-trip with receive
console.log('\n=== Round-trip Test ==='); console.log('\n=== Round-trip Test ===');
const roundTripData = { const roundTripData = {
correlation_id: 'roundtrip-' + Date.now(), correlation_id: 'roundtrip-' + crypto.randomUUID(),
msg_id: 'msg-' + Date.now(), msg_id: 'msg-' + crypto.randomUUID(),
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
send_to: '/test/dictionary', send_to: '/test/dictionary',
msg_purpose: 'test', msg_purpose: 'test',
sender_name: 'js-test', sender_name: 'js-test',
sender_id: 'sender-' + Date.now(), sender_id: 'sender-' + crypto.randomUUID(),
receiver_name: 'js-receiver', receiver_name: 'js-receiver',
receiver_id: 'receiver-' + Date.now(), receiver_id: 'receiver-' + crypto.randomUUID(),
reply_to: '', reply_to: '',
reply_to_msg_id: '', reply_to_msg_id: '',
broker_url: TEST_BROKER_URL, broker_url: TEST_BROKER_URL,

View File

@@ -3,7 +3,8 @@
* Tests the smartsend function with dictionary payloads * Tests the smartsend function with dictionary payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_SUBJECT = '/test/dictionary'; const TEST_SUBJECT = '/test/dictionary';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
async function runTest() { async function runTest() {
console.log('=== JavaScript Dictionary Sender Test ===\n'); console.log('=== JavaScript Dictionary Sender Test ===\n');
const correlationId = NATSBridge.uuidv4(); const correlationId = crypto.randomUUID();
console.log(`Correlation ID: ${correlationId}`); console.log(`Correlation ID: ${correlationId}`);
console.log(`Subject: ${TEST_SUBJECT}`); console.log(`Subject: ${TEST_SUBJECT}`);
console.log(`Broker URL: ${TEST_BROKER_URL}\n`); console.log(`Broker URL: ${TEST_BROKER_URL}\n`);

View File

@@ -0,0 +1,216 @@
/**
* JavaScript Mix Payloads Receiver Test
* Tests the smartreceive function with mixed payload types
*/
const NATSBridge = require('../src/natsbridge.js');
const nats = require('nats');
const crypto = require('crypto');
const TEST_SUBJECT = '/test/mix';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
async function runTest() {
console.log('=== JavaScript Mix Payloads Receiver Test ===\n');
const correlationId = crypto.randomUUID();
console.log(`Correlation ID: ${correlationId}`);
console.log(`Subject: ${TEST_SUBJECT}`);
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
// Expected test data - same as sender
const expectedTextData = 'Hello, NATSBridge!';
const expectedDictData = { key1: 'value1', key2: 42, nested: { a: 1, b: 2 } };
const expectedBinaryData = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]); // PNG header
const expectedTableData = [
{ id: 1, name: 'Alice', age: 30 },
{ id: 2, name: 'Bob', age: 25 },
{ id: 3, name: 'Charlie', age: 35 }
];
const expectedDatanames = ['message', 'config', 'image', 'users'];
const expectedTypes = ['text', 'dictionary', 'image', 'table'];
let testPassed = true;
let messagesReceived = 0;
const receivedPayloads = [];
try {
// Connect to NATS
console.log('Connecting to NATS server...');
const nc = await nats.connect({ servers: TEST_BROKER_URL });
console.log('✅ Connected to NATS server\n');
// Set up message subscription
const subscription = nc.subscribe(TEST_SUBJECT);
// Wait for messages with timeout
const messagePromise = new Promise(async (resolve, reject) => {
const timeout = setTimeout(() => {
resolve('timeout');
}, 10000); // 10 second timeout
(async () => {
for await (const msg of subscription) {
clearTimeout(timeout);
messagesReceived++;
console.log(`\n=== Message ${messagesReceived} Received ===`);
console.log(`Raw payload length: ${msg.payload.length} bytes`);
try {
// Process the message using smartreceive
const envelope = await NATSBridge.smartreceive(msg, {
fileserver_download_handler: NATSBridge.fetchWithBackoff,
max_retries: 5,
base_delay: 100,
max_delay: 5000
});
console.log(`Correlation ID: ${envelope.correlation_id}`);
console.log(`Message ID: ${envelope.msg_id}`);
console.log(`Number of payloads: ${envelope.payloads.length}`);
receivedPayloads.push(envelope);
// Validate envelope structure
console.log('\n=== Envelope Validation ===');
if (envelope.payloads.length < 4) {
console.log(`❌ Expected at least 4 payloads, got ${envelope.payloads.length}`);
testPassed = false;
} else {
console.log(`✅ Correct number of payloads: ${envelope.payloads.length}`);
}
// Validate each payload
for (let i = 0; i < envelope.payloads.length; i++) {
const [dataname, data, dataType] = envelope.payloads[i];
console.log(`\n--- Payload ${i + 1}: ${dataname} (type: ${dataType}) ---`);
// Check dataname
if (i < expectedDatanames.length && dataname !== expectedDatanames[i]) {
console.log(`❌ Expected dataname '${expectedDatanames[i]}', got '${dataname}'`);
testPassed = false;
} else {
console.log(`✅ Correct dataname: ${dataname}`);
}
// Check data type
if (i < expectedTypes.length && dataType !== expectedTypes[i]) {
console.log(`❌ Expected type '${expectedTypes[i]}', got '${dataType}'`);
testPassed = false;
} else {
console.log(`✅ Correct type: ${dataType}`);
}
// Validate data based on type
if (dataType === 'text') {
if (typeof data === 'string' && data === expectedTextData) {
console.log(`✅ Text data verified: "${data}"`);
} else {
console.log(`❌ Text data mismatch. Expected: "${expectedTextData}", Got: "${data}"`);
testPassed = false;
}
} else if (dataType === 'dictionary') {
if (typeof data === 'object' && JSON.stringify(data) === JSON.stringify(expectedDictData)) {
console.log(`✅ Dictionary data verified`);
console.log(` Keys: ${Object.keys(data).join(', ')}`);
} else {
console.log(`❌ Dictionary data mismatch`);
console.log(` Expected: ${JSON.stringify(expectedDictData)}`);
console.log(` Got: ${JSON.stringify(data)}`);
testPassed = false;
}
} else if (dataType === 'image') {
if (data instanceof Buffer || data instanceof Uint8Array) {
const dataBuffer = Buffer.isBuffer(data) ? data : Buffer.from(data);
if (dataBuffer.length === expectedBinaryData.length) {
let dataMatch = true;
for (let j = 0; j < expectedBinaryData.length; j++) {
if (dataBuffer[j] !== expectedBinaryData[j]) {
dataMatch = false;
break;
}
}
if (dataMatch) {
console.log(`✅ Image data verified (${dataBuffer.length} bytes)`);
} else {
console.log(`❌ Image data mismatch`);
testPassed = false;
}
} else {
console.log(`❌ Image data length mismatch. Expected: ${expectedBinaryData.length}, Got: ${dataBuffer.length}`);
testPassed = false;
}
} else {
console.log(`❌ Image data is not a Buffer or Uint8Array`);
testPassed = false;
}
} else if (dataType === 'table') {
// For table data, check if it's an Arrow table-like object
if (data && typeof data === 'object') {
// Arrow tables have specific properties
if (data.numRows !== undefined && data.numCols !== undefined) {
console.log(`✅ Table data verified`);
console.log(` Rows: ${data.numRows}, Columns: ${data.numCols}`);
} else {
console.log(`⚠️ Table data received but not standard Arrow format`);
console.log(` Keys: ${Object.keys(data).join(', ')}`);
}
} else {
console.log(`❌ Table data is not a valid object`);
testPassed = false;
}
}
}
// Stop after receiving at least one valid message
if (messagesReceived >= 1) {
resolve('done');
}
} catch (error) {
console.error(`❌ Error processing message: ${error.message}`);
console.error(error.stack);
testPassed = false;
resolve('error');
}
}
})();
});
console.log('Waiting for messages...\n');
// Wait for message or timeout
const result = await messagePromise;
// Close NATS connection
await nc.close();
console.log('\n✅ NATS connection closed');
// Final result
console.log('\n=== Test Result ===');
if (messagesReceived === 0) {
console.log('❌ NO MESSAGES RECEIVED');
console.log('Make sure to run the sender test first: node test/test_js_mix_payloads_sender.js');
process.exit(1);
} else if (result === 'error') {
console.log('❌ ERROR PROCESSING MESSAGES');
process.exit(1);
} else if (testPassed) {
console.log('✅ ALL TESTS PASSED');
process.exit(0);
} else {
console.log('❌ SOME TESTS FAILED');
process.exit(1);
}
} catch (error) {
console.error('❌ Test failed with error:', error.message);
console.error(error.stack);
process.exit(1);
}
}
runTest();

View File

@@ -3,7 +3,8 @@
* Tests the smartsend function with mixed payload types * Tests the smartsend function with mixed payload types
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_SUBJECT = '/test/mix'; const TEST_SUBJECT = '/test/mix';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
async function runTest() { async function runTest() {
console.log('=== JavaScript Mix Payloads Sender Test ===\n'); console.log('=== JavaScript Mix Payloads Sender Test ===\n');
const correlationId = NATSBridge.uuidv4(); const correlationId = crypto.randomUUID();
console.log(`Correlation ID: ${correlationId}`); console.log(`Correlation ID: ${correlationId}`);
console.log(`Subject: ${TEST_SUBJECT}`); console.log(`Subject: ${TEST_SUBJECT}`);
console.log(`Broker URL: ${TEST_BROKER_URL}\n`); console.log(`Broker URL: ${TEST_BROKER_URL}\n`);

View File

@@ -3,7 +3,8 @@
* Tests the smartreceive function with table (Arrow IPC) payloads * Tests the smartreceive function with table (Arrow IPC) payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
@@ -42,15 +43,15 @@ async function runTest() {
const arrowBuffer = Buffer.from(combined); const arrowBuffer = Buffer.from(combined);
const testData = { const testData = {
correlation_id: 'js-table-receiver-' + Date.now(), correlation_id: 'js-table-receiver-' + crypto.randomUUID(),
msg_id: 'msg-' + Date.now(), msg_id: 'msg-' + crypto.randomUUID(),
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
send_to: '/test/table', send_to: '/test/table',
msg_purpose: 'test', msg_purpose: 'test',
sender_name: 'js-table-test', sender_name: 'js-table-test',
sender_id: 'sender-' + Date.now(), sender_id: 'sender-' + crypto.randomUUID(),
receiver_name: 'js-receiver', receiver_name: 'js-receiver',
receiver_id: 'receiver-' + Date.now(), receiver_id: 'receiver-' + crypto.randomUUID(),
reply_to: '', reply_to: '',
reply_to_msg_id: '', reply_to_msg_id: '',
broker_url: TEST_BROKER_URL, broker_url: TEST_BROKER_URL,

View File

@@ -3,7 +3,8 @@
* Tests the smartsend function with table (Arrow IPC) payloads * Tests the smartsend function with table (Arrow IPC) payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_SUBJECT = '/test/table'; const TEST_SUBJECT = '/test/table';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
async function runTest() { async function runTest() {
console.log('=== JavaScript Table Sender Test ===\n'); console.log('=== JavaScript Table Sender Test ===\n');
const correlationId = NATSBridge.uuidv4(); const correlationId = crypto.randomUUID();
console.log(`Correlation ID: ${correlationId}`); console.log(`Correlation ID: ${correlationId}`);
console.log(`Subject: ${TEST_SUBJECT}`); console.log(`Subject: ${TEST_SUBJECT}`);
console.log(`Broker URL: ${TEST_BROKER_URL}\n`); console.log(`Broker URL: ${TEST_BROKER_URL}\n`);

View File

@@ -3,7 +3,8 @@
* Tests the smartreceive function with text payloads * Tests the smartreceive function with text payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
@@ -13,22 +14,22 @@ async function runTest() {
// Create a mock NATS message with text payload // Create a mock NATS message with text payload
const testData = { const testData = {
correlation_id: 'test-receiver-' + Date.now(), correlation_id: 'test-receiver-' + crypto.randomUUID(),
msg_id: 'msg-' + Date.now(), msg_id: 'msg-' + crypto.randomUUID(),
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
send_to: '/test/text', send_to: '/test/text',
msg_purpose: 'test', msg_purpose: 'test',
sender_name: 'js-text-test', sender_name: 'js-text-test',
sender_id: 'sender-' + Date.now(), sender_id: 'sender-' + crypto.randomUUID(),
receiver_name: 'js-receiver', receiver_name: 'js-receiver',
receiver_id: 'receiver-' + Date.now(), receiver_id: 'receiver-' + crypto.randomUUID(),
reply_to: '', reply_to: '',
reply_to_msg_id: '', reply_to_msg_id: '',
broker_url: TEST_BROKER_URL, broker_url: TEST_BROKER_URL,
metadata: {}, metadata: {},
payloads: [ payloads: [
{ {
id: 'payload-' + Date.now(), id: 'payload-' + crypto.randomUUID(),
dataname: 'message', dataname: 'message',
payload_type: 'text', payload_type: 'text',
transport: 'direct', transport: 'direct',
@@ -115,15 +116,15 @@ async function runTest() {
// Test with multiple text payloads // Test with multiple text payloads
console.log('\n=== Multiple Text Payloads Test ==='); console.log('\n=== Multiple Text Payloads Test ===');
const multiTestData = { const multiTestData = {
correlation_id: 'multi-receiver-' + Date.now(), correlation_id: 'multi-receiver-' + crypto.randomUUID(),
msg_id: 'msg-' + Date.now(), msg_id: 'msg-' + crypto.randomUUID(),
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
send_to: '/test/text', send_to: '/test/text',
msg_purpose: 'test', msg_purpose: 'test',
sender_name: 'js-text-test', sender_name: 'js-text-test',
sender_id: 'sender-' + Date.now(), sender_id: 'sender-' + crypto.randomUUID(),
receiver_name: 'js-receiver', receiver_name: 'js-receiver',
receiver_id: 'receiver-' + Date.now(), receiver_id: 'receiver-' + crypto.randomUUID(),
reply_to: '', reply_to: '',
reply_to_msg_id: '', reply_to_msg_id: '',
broker_url: TEST_BROKER_URL, broker_url: TEST_BROKER_URL,

View File

@@ -3,7 +3,8 @@
* Tests the smartsend function with text payloads * Tests the smartsend function with text payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const crypto = require('crypto');
const TEST_SUBJECT = '/test/text'; const TEST_SUBJECT = '/test/text';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
async function runTest() { async function runTest() {
console.log('=== JavaScript Text Sender Test ===\n'); console.log('=== JavaScript Text Sender Test ===\n');
const correlationId = NATSBridge.uuidv4(); const correlationId = crypto.randomUUID();
console.log(`Correlation ID: ${correlationId}`); console.log(`Correlation ID: ${correlationId}`);
console.log(`Subject: ${TEST_SUBJECT}`); console.log(`Subject: ${TEST_SUBJECT}`);
console.log(`Broker URL: ${TEST_BROKER_URL}\n`); console.log(`Broker URL: ${TEST_BROKER_URL}\n`);

View File

@@ -14,7 +14,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Binary Receiver Test ===\n') print('=== MicroPython Binary Receiver Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
# Create mock NATS message with binary payloads # Create mock NATS message with binary payloads
image_data = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) # PNG header image_data = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) # PNG header

View File

@@ -13,7 +13,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
TEST_SUBJECT = '/test/binary' TEST_SUBJECT = '/test/binary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Binary Sender Test ===\n') print('=== MicroPython Binary Sender Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
correlation_id = 'mpy-binary-test-' + _generate_uuid() correlation_id = 'mpy-binary-test-' + _generate_uuid()
print(f'Correlation ID: {correlation_id}') print(f'Correlation ID: {correlation_id}')
print(f'Subject: {TEST_SUBJECT}') print(f'Subject: {TEST_SUBJECT}')

View File

@@ -13,7 +13,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Dictionary Receiver Test ===\n') print('=== MicroPython Dictionary Receiver Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
# Create a mock NATS message with dictionary payloads # Create a mock NATS message with dictionary payloads
import base64 import base64

View File

@@ -13,7 +13,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
TEST_SUBJECT = '/test/dictionary' TEST_SUBJECT = '/test/dictionary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Dictionary Sender Test ===\n') print('=== MicroPython Dictionary Sender Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
correlation_id = 'mpy-dict-test-' + _generate_uuid() correlation_id = 'mpy-dict-test-' + _generate_uuid()
print(f'Correlation ID: {correlation_id}') print(f'Correlation ID: {correlation_id}')
print(f'Subject: {TEST_SUBJECT}') print(f'Subject: {TEST_SUBJECT}')

View File

@@ -13,7 +13,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Text Receiver Test ===\n') print('=== MicroPython Text Receiver Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
# Create a mock NATS message with text payload # Create a mock NATS message with text payload
test_text = 'Hello, NATSBridge! This is a test message.' test_text = 'Hello, NATSBridge! This is a test message.'

View File

@@ -12,7 +12,7 @@ import os
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
TEST_SUBJECT = '/test/text' TEST_SUBJECT = '/test/text'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Text Sender Test ===\n') print('=== MicroPython Text Sender Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
correlation_id = 'mpy-text-test-' + _generate_uuid() correlation_id = 'mpy-text-test-' + _generate_uuid()
print(f'Correlation ID: {correlation_id}') print(f'Correlation ID: {correlation_id}')
print(f'Subject: {TEST_SUBJECT}') print(f'Subject: {TEST_SUBJECT}')

View File

@@ -12,7 +12,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')

View File

@@ -11,7 +11,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/binary' TEST_SUBJECT = '/test/binary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -11,7 +11,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')

View File

@@ -11,7 +11,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/dictionary' TEST_SUBJECT = '/test/dictionary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -11,7 +11,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/mix' TEST_SUBJECT = '/test/mix'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -10,7 +10,7 @@ import os
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/table' TEST_SUBJECT = '/test/table'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -11,7 +11,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')

View File

@@ -10,7 +10,7 @@ import os
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/text' TEST_SUBJECT = '/test/text'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')