Minor updates

This commit is contained in:
Andrey Sobolev
2025-10-01 10:08:28 +07:00
parent ac73f57d49
commit a61ba16424
2 changed files with 98 additions and 93 deletions
+34 -2
View File
@@ -7,15 +7,17 @@ This directory contains comprehensive examples demonstrating various aspects of
Before running any example, make sure you have:
1. Built the project:
```bash
node common/scripts/install-run-rush.js build
```
2. Either start a standalone network server:
```bash
cd pods/network-pod && rushx dev
```
Or let the example start its own network server (most examples do this).
3. Run an example:
@@ -26,9 +28,11 @@ Before running any example, make sure you have:
## Examples
### 01 - Basic Container with Request/Response
**File**: `01-basic-container-request-response.ts`
Learn the fundamentals of creating containers that handle various operations. This example shows:
- Container implementation basics
- Request/response pattern
- State management within containers
@@ -39,9 +43,11 @@ Learn the fundamentals of creating containers that handle various operations. Th
---
### 02 - Event Broadcasting
**File**: `02-event-broadcasting.ts`
Demonstrates real-time event broadcasting to multiple connected clients. Features:
- Multiple clients connecting to the same container
- Broadcasting events to all connected clients
- Chat room implementation
@@ -52,9 +58,11 @@ Demonstrates real-time event broadcasting to multiple connected clients. Feature
---
### 03 - Multi-Tenant Container Management
**File**: `03-multi-tenant.ts`
Shows how to build multi-tenant applications with isolated workspaces. Includes:
- Per-tenant container isolation
- Label-based container selection
- Tenant-specific data management
@@ -65,9 +73,11 @@ Shows how to build multi-tenant applications with isolated workspaces. Includes:
---
### 04 - Complete Production Setup
**File**: `04-complete-production-setup.ts`
A comprehensive production-ready example with:
- Multiple redundant agents for high availability
- Health monitoring and metrics collection
- Event monitoring for observability
@@ -80,9 +90,11 @@ A comprehensive production-ready example with:
---
### 05 - Error Handling and Retry Logic
**File**: `05-error-handling-retry.ts`
Advanced error handling patterns including:
- Exponential backoff retry logic
- Timeout handling
- Graceful degradation with fallbacks
@@ -94,9 +106,11 @@ Advanced error handling patterns including:
---
### Custom Timeout Example
**File**: `custom-timeout-example.ts`
Shows how to configure different timeouts for various environments:
- Development vs production timeouts
- Connection timeout configuration
- Keep-alive timeout settings
@@ -106,9 +120,11 @@ Shows how to configure different timeouts for various environments:
---
### High Availability (HA) Stateless Container Example
**File**: `ha-stateless-container-example.ts`
Demonstrates automatic failover with stateless containers:
- Multiple agents competing for the same container UUID
- Automatic leader election
- Failover when primary fails
@@ -119,17 +135,23 @@ Demonstrates automatic failover with stateless containers:
## Example Categories
### For Beginners
Start with these examples to learn the basics:
1. `01-basic-container-request-response.ts`
2. `custom-timeout-example.ts`
### For Application Developers
Build real applications with these patterns:
1. `02-event-broadcasting.ts` - Real-time features
2. `03-multi-tenant.ts` - SaaS applications
### For DevOps/Production
Production-ready patterns:
1. `04-complete-production-setup.ts` - Full production setup
2. `05-error-handling-retry.ts` - Robust error handling
3. `ha-stateless-container-example.ts` - High availability
@@ -137,18 +159,23 @@ Production-ready patterns:
## Running Examples
### Run a single example:
```bash
npx ts-node examples/01-basic-container-request-response.ts
```
### Run with custom network host:
Most examples connect to `localhost:3737` by default. To use a different host:
```typescript
const client = createNetworkClient('your-host:3737')
```
### Debug mode:
Run with longer timeouts for debugging:
```bash
NODE_ENV=development npx ts-node examples/01-basic-container-request-response.ts
```
@@ -174,7 +201,7 @@ class MyContainer implements Container {
async ping(): Promise<void> {}
async terminate(): Promise<void> {}
connect(clientId: ClientUuid, broadcast: (data: any) => Promise<void>): void {}
disconnect(clientId: ClientUuid): void {}
}
@@ -220,21 +247,25 @@ await server.start(agent)
## Troubleshooting
### Connection refused
- Ensure the network server is running on the specified port
- Check firewall settings
- Verify the correct host and port are being used
### Container not found
- Ensure the agent is registered with the network
- Check that the container kind matches what the agent supports
- Verify the agent is still alive (check agent health)
### Timeout errors
- Increase timeout values for debugging: `createNetworkClient('host:port', 3600)`
- Check network connectivity
- Verify services are responding to ping/health checks
### Type errors in examples
The examples use dynamic container kinds (strings) which may show TypeScript errors. This is expected and doesn't affect functionality. In production, define proper types:
```typescript
@@ -260,6 +291,7 @@ To contribute a new example:
6. Submit a pull request
Example template structure:
- Header comment with description and usage
- Imports
- Container implementation (if applicable)