Using a Custom Backend
If the built-in backends don't fit your infrastructure, you can register a third-party or custom backend implementation. This guide covers how to wire one up; for building your own, see Writing a Custom Backend.
When to Use a Custom Backend
- Your infrastructure uses a messaging system Strata doesn't ship with (AMQP, Kafka, gRPC, etc.)
- A team or community has published a Strata backend package you want to use
- You've written your own backend and need to plug it in
Registering a Backend
Call registerBackend() on your service or client before calling start(). The first argument is the name you'll reference in config; the second is the backend class.
With a Service
import { StrataService } from '@strata-js/strata';
import { MyBackend } from './backends/myBackend.js';
const service = new StrataService({
service: { serviceGroup: 'UserService' },
backend: {
type: 'my-backend',
connectionUrl: 'amqp://localhost:5672',
},
});
service.registerBackend('my-backend', MyBackend);
await service.start();With a Client
import { StrataClient } from '@strata-js/strata';
import { MyBackend } from './backends/myBackend.js';
const client = new StrataClient({
backend: {
type: 'my-backend',
connectionUrl: 'amqp://localhost:5672',
},
});
client.registerBackend('my-backend', MyBackend);
await client.start();How the type Field Works
The type field in your backend config is a lookup key. When Strata initializes, it finds the backend class registered under that name and instantiates it. The built-in backends (redis, redis-streams, null) are pre-registered; custom backends need an explicit registerBackend() call.
Important: Register Before start()
registerBackend() must be called before start(). During startup, Strata resolves the type string to a backend class, instantiates it, and calls init(). If the backend isn't registered yet, startup fails.
Next Steps
- Writing a Custom Backend -- how to build one from scratch.
- Backends -- built-in backend reference and common configuration.
- Application -- full
registerBackend()API docs.