@eggjs/cluster
Version:
cluster manager for egg
96 lines (95 loc) • 2.33 kB
TypeScript
import { WorkerManager } from "./worker_manager.js";
import { Master } from "../master.js";
//#region src/utils/messenger.d.ts
type MessageCharacter = 'agent' | 'app' | 'master' | 'parent';
interface MessageBody {
action: string;
data?: unknown;
to?: MessageCharacter;
from?: MessageCharacter;
/**
* @deprecated Keep compatible, please use receiverWorkerId instead
*/
receiverPid?: string;
receiverWorkerId?: string;
senderWorkerId?: string;
}
/**
* master messenger, provide communication between parent, master, agent and app.
*
* ┌────────┐
* │ parent │
* /└────────┘\
* / | \
* / ┌────────┐ \
* / │ master │ \
* / └────────┘ \
* / / \ \
* ┌───────┐ ┌───────┐
* │ agent │ ------- │ app │
* └───────┘ └───────┘
*
*
* in app worker
*
* ```js
* process.send({
* action: 'xxx',
* data: '',
* to: 'agent/master/parent', // default to agent
* });
* ```
*
* in agent worker
*
* ```js
* process.send({
* action: 'xxx',
* data: '',
* to: 'app/master/parent', // default to app
* });
* ```
*
* in parent
*
* ```js
* process.send({
* action: 'xxx',
* data: '',
* to: 'app/agent/master', // default to master
* });
* ```
*/
declare class Messenger {
#private;
constructor(master: Master, workerManager: WorkerManager);
/**
* send message
* @param {Object} data message body
* - {String} from from who
* - {String} to to who
*/
send(data: MessageBody): void;
/**
* send message to master self
* @param {Object} data message body
*/
sendToMaster(data: MessageBody): void;
/**
* send message to parent process
* @param {Object} data message body
*/
sendToParent(data: MessageBody): void;
/**
* send message to app worker
* @param {Object} data message body
*/
sendToAppWorker(data: MessageBody): void;
/**
* send message to agent worker
* @param {Object} data message body
*/
sendToAgentWorker(data: MessageBody): void;
}
//#endregion
export { MessageBody, Messenger };