1.7.0 • Published 6 months ago
@rc-microcap/core v1.7.0
@rc-microcap/core
This package provides the core framework for the MicroCAP (Micro Collaborative Agent Platform) TypeScript implementation. It includes the necessary interfaces, base classes, and ZeroMQ communication logic to build distributed, message-based applications using the actor model.
Features
- Actor base class (
Actor
) - Runtime management (
RuntimeFactory
,ZmqRuntime
) - Publish/Subscribe and Request/Response messaging patterns
- ZeroMQ-based communication (
ZmqActorConnector
,ZmqActorSender
) - Service discovery via Directory Service integration
- Protocol Buffer support for type-safe messaging
Installation
npm install @rc-microcap/core
Usage
This package provides the building blocks for your MicroCAP applications. You will typically need to run the @rc-microcap/zmq-broker
and @rc-microcap/zmq-directory
services for communication and discovery.
import { Actor, RuntimeFactory } from '@rc-microcap/core';
// Define your actor
class MyActor extends Actor {
constructor() {
super("MyActor", "An example actor");
}
async onStart() {
console.log(`${this.name} started!`);
// Initialization logic
}
async onTextMessage(topic: string, message: string) {
console.log(`Received text message on topic ${topic}: ${message}`);
return true; // Keep running
}
}
// --- Main application ---
async function main() {
const runtime = RuntimeFactory.getRuntime(); // Get default ZMQ runtime
const actor = new MyActor();
await runtime.register(actor);
await runtime.connect(); // Connects to Broker and Directory
console.log('Application started. Press Ctrl+C to exit.');
// Keep the application running (example)
process.on('SIGINT', async () => {
console.log('Shutting down...');
await runtime.disconnect();
process.exit(0);
});
}
main().catch(console.error);
Full Documentation
For comprehensive documentation, usage guides, and examples, please refer to the main MicroCAP repository:
https://github.com/rajan-chari/microcap/tree/main/typescript