0.1.2 • Published 6 months ago
@magicbutton.cloud/nats-transport v0.1.2
NATS Transport Provider
NATS transport provider for the Magic Button Cloud messaging library.
Part of the Magic Button Cloud Providers collection.
Installation
# With npm
npm install @magicbutton.cloud/nats-transport
# With pnpm
pnpm add @magicbutton.cloud/nats-transport
# With yarn
yarn add @magicbutton.cloud/nats-transportUsage
import { Client } from '@magicbutton.cloud/messaging';
import { NatsTransportFactory } from '@magicbutton.cloud/nats-transport';
// Create your transport factory
const transportFactory = new NatsTransportFactory();
// Create a client with your transport
const client = Client.create({
transportFactory,
transportConfig: {
servers: ['nats://localhost:4222'],
subjects: {
requests: 'myapp.requests',
events: 'myapp.events'
}
}
});
// Connect the client
await client.connect();
// Make a request
const response = await client.request('getUsers', { filter: 'active' });
// Subscribe to events
client.on('userAdded', (user) => {
console.log('New user added:', user);
});
// Disconnect when done
await client.disconnect();Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
| servers | string[] | Yes | Array of NATS server URLs |
| token | string | No | Authentication token |
| user | string | No | Username for authentication |
| pass | string | No | Password for authentication |
| subjects.requests | string | No | Base subject for requests (default: 'messaging.requests') |
| subjects.events | string | No | Base subject for events (default: 'messaging.events') |
| connectTimeout | number | No | Connection timeout in milliseconds (default: 10000) |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
0.1.2
6 months ago