apollo-rust-client 0.7.0

A Rust client for Apollo configuration center
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
[中文简体]../zh-CN/Installation.md | [中文繁體]../zh-TW/Installation.md
[Back to Home](Home.md)

# Installation

This guide covers installation and setup for the Apollo Rust Client across different platforms and environments.

## Requirements

### System Requirements

#### Native Rust

- **Rust Version**: 1.85.0 or later (required for Edition 2024)
- **Operating Systems**: Linux, macOS, Windows
- **Architecture**: x86_64, ARM64
- **Dependencies**: Standard Rust toolchain

#### WebAssembly

- **Node.js**: 16.0.0 or later (for Node.js environments)
- **Browsers**: Modern browsers with WebAssembly support
- **Build Tools**: `wasm-pack` for building from source

### Network Requirements

- **Apollo Server**: Access to Apollo Configuration Center
- **Protocols**: HTTP/HTTPS support
- **Ports**: Configurable (typically 8080, 8090, or 443)

## Rust Installation

### Using Cargo

Add the Apollo Rust Client to your `Cargo.toml`:

```toml
[dependencies]
apollo-rust-client = "0.7.0"
```

### Using Cargo Add

Alternatively, use the `cargo add` command:

```bash
cargo add apollo-rust-client
```

### Version Specification

#### Latest Version

```toml
[dependencies]
apollo-rust-client = "0.7.0"
```

#### Version Range

```toml
[dependencies]
apollo-rust-client = "^0.7.0"  # Compatible with 0.7.x
```

#### Specific Version

```toml
[dependencies]
apollo-rust-client = "=0.7.0"  # Exact version
```

### Feature Flags

The library supports conditional compilation for different platforms:

```toml
[dependencies]
apollo-rust-client = { version = "0.7.0", features = ["native-tls"] }
```

Available features:

- `native-tls`: Standard features for native Rust (default)
- `rustls`: Rustls support for native Rust (alternative to native-tls)

## WebAssembly Installation

### NPM Package

Install the WebAssembly package via npm:

```bash
npm install @qqiao/apollo-rust-client
```

### Yarn Package Manager

```bash
yarn add @qqiao/apollo-rust-client
```

### Package Information

- **Package Name**: `@qqiao/apollo-rust-client`
- **Version**: 0.7.0
- **Registry**: [NPM Registry]https://www.npmjs.com/package/@qqiao/apollo-rust-client
- **Bundle Size**: Optimized for browser environments

### TypeScript Support

The package includes TypeScript definitions:

```typescript
import { Client, ClientConfig } from "@qqiao/apollo-rust-client";

const config = new ClientConfig(
  "app-id",
  "http://apollo-server:8080",
  "default"
);
const client = new Client(config);
```

## Verification

### Rust Verification

Create a simple test to verify the installation:

```rust
use apollo_rust_client::{Client, client_config::ClientConfig};

fn main() {
    let config = ClientConfig {
        app_id: "test-app".to_string(),
        config_server: "http://localhost:8080".to_string(),
        cluster: "default".to_string(),
        secret: None,
        cache_dir: None,
        label: None,
        ip: None,
    };

    let client = Client::new(config);
    println!("Apollo Rust Client installed successfully!");
}
```

Run the test:

```bash
cargo run
```

### WebAssembly Verification

Create a simple JavaScript test:

```javascript
import { Client, ClientConfig } from "@qqiao/apollo-rust-client";

async function test() {
  try {
    const config = new ClientConfig(
      "test-app",
      "http://localhost:8080",
      "default"
    );
    const client = new Client(config);

    console.log("Apollo Rust Client (WASM) installed successfully!");

    // Clean up
    client.free();
    config.free();
  } catch (error) {
    console.error("Installation verification failed:", error);
  }
}

test();
```

## Building from Source

### Prerequisites

#### Rust Toolchain

```bash
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install required targets
rustup target add wasm32-unknown-unknown
```

#### WebAssembly Tools

```bash
# Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Or via cargo
cargo install wasm-pack
```

### Building for Native Rust

```bash
# Clone the repository
git clone https://github.com/qqiao/apollo-rust-client.git
cd apollo-rust-client

# Build the library
cargo build --release

# Run tests
cargo test
```

### Building for WebAssembly

```bash
# Build for Node.js
wasm-pack build --target nodejs

# Build for browsers
wasm-pack build --target web

# Build for bundlers (webpack, etc.)
wasm-pack build --target bundler
```

### Custom Build Configuration

Create a custom build with specific features:

```bash
# Build with specific features
cargo build --release --features "custom-feature"

# Build for specific target
cargo build --release --target wasm32-unknown-unknown
```

## Platform-Specific Setup

### Linux

#### Ubuntu/Debian

```bash
# Install system dependencies
sudo apt-get update
sudo apt-get install build-essential pkg-config libssl-dev

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

#### CentOS/RHEL

```bash
# Install system dependencies
sudo yum groupinstall "Development Tools"
sudo yum install openssl-devel

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### macOS

#### Using Homebrew

```bash
# Install Xcode command line tools
xcode-select --install

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### Windows

#### Using Rustup

```powershell
# Download and run rustup-init.exe from https://rustup.rs/

# Install Visual Studio Build Tools or Visual Studio with C++ support
# Download from https://visualstudio.microsoft.com/downloads/
```

#### Using Chocolatey

```powershell
# Install Chocolatey first, then:
choco install rust

# Install Visual Studio Build Tools
choco install visualstudio2019buildtools
```

## Configuration

### Environment Variables

Set up environment variables for easier configuration:

```bash
# Required variables
export APP_ID="your-app-id"
export APOLLO_CONFIG_SERVICE="http://your-apollo-server:8080"

# Optional variables
export IDC="default"
export APOLLO_ACCESS_KEY_SECRET="your-secret-key"
export APOLLO_LABEL="production,canary"
export APOLLO_CACHE_DIR="/opt/apollo/cache"
```

### Configuration Files

Create a configuration file for your application:

```toml
# apollo-config.toml
[apollo]
app_id = "your-app-id"
config_server = "http://your-apollo-server:8080"
cluster = "default"
secret = "your-secret-key"
cache_dir = "/opt/apollo/cache"
label = "production,canary"
ip = "192.168.1.100"
```

## Troubleshooting

### Common Issues

#### Network Connectivity

```bash
# Test Apollo server connectivity
curl -v http://your-apollo-server:8080/configs/your-app-id/default/application
```

#### Permission Issues

```bash
# Fix cache directory permissions
sudo mkdir -p /opt/apollo/cache
sudo chown -R $USER:$USER /opt/apollo/cache
```

#### Build Failures

##### Missing Dependencies

```bash
# Linux: Install build dependencies
sudo apt-get install build-essential pkg-config libssl-dev

# macOS: Install Xcode command line tools
xcode-select --install
```

##### WebAssembly Build Issues

```bash
# Update wasm-pack
cargo install wasm-pack --force

# Clean and rebuild
cargo clean
wasm-pack build --target nodejs
```

### Debug Mode

Enable debug logging for troubleshooting:

```rust
// Set environment variable
std::env::set_var("RUST_LOG", "apollo_rust_client=debug");

// Initialize logger
env_logger::init();
```

```javascript
// Enable debug logging in browser console
localStorage.setItem("debug", "apollo-rust-client:*");
```

## Version History

### Current Version: 0.7.0

#### New Features

- Typed namespaces with automatic format detection
- Event listeners for real-time configuration updates
- Enhanced error handling with comprehensive error types
- Improved WebAssembly support with better memory management

#### Breaking Changes

- Namespace API now returns typed enum instead of raw cache
- Event listener API has changed for better type safety
- Some configuration options have been renamed for clarity

### Previous Versions

#### 0.4.x

- Basic namespace support
- File-based caching
- WebAssembly support

#### 0.3.x

- Initial release
- Basic Apollo client functionality
- Properties format support

## Next Steps

After installation, proceed to:

1. **[Configuration]Configuration.md** - Set up your client configuration
2. **[Rust Usage]Rust-Usage.md** - Learn how to use the library in Rust
3. **[JavaScript Usage]JavaScript-Usage.md** - Learn how to use the library in JavaScript
4. **[Features]Features.md** - Explore all available features

## Support

If you encounter issues during installation:

1. Check the [GitHub Issues]https://github.com/qqiao/apollo-rust-client/issues
2. Review the [Documentation]https://docs.rs/apollo-rust-client
3. Join the community discussions
4. Submit a bug report if needed