WorkerMessage

WorkerMessage

WorkerMessage

Package: @vendure/core File: types.ts

A class which is used to define the contract between the Vendure server and the worker process. Used by the WorkerService send method.

Example

export class ReindexMessage extends WorkerMessage<{ ctx: RequestContext }, boolean> {
    static readonly pattern = 'Reindex';
}

// in a Service running on the main process
class MyService {

     constructor(private workerService: WorkerService) {}

     reindex(ctx: RequestContext): Observable<boolean>> {
         return this.workerService.send(new ReindexMessage({ ctx }))
     }
}

// in a microservice Controller on the worker process
class MyController {

     @MessagePattern(ReindexMessage.pattern)
     reindex({ ctx: rawContext }: ReindexMessage['data']): Observable<ReindexMessage['response']> {
        // ... some long-running workload
     }
}

Signature

class WorkerMessage<T, R> {
  static readonly static readonly pattern: string;
  constructor(data: T)
  response: R;
}

Members

pattern

static readonly property
type:
string

constructor

method
type:
(data: T) => WorkerMessage

response

property
type:
R