feat: 完善消息发布。
This commit is contained in:
@ -2,7 +2,7 @@ import debug from 'debug';
|
||||
import { EventEmitter } from 'events';
|
||||
import IORedis, { Redis } from 'ioredis';
|
||||
import { from, fromEvent, Observable } from 'rxjs';
|
||||
import { filter, map, switchMap, takeWhile, tap } from 'rxjs/operators';
|
||||
import { filter, map, share, switchMap, takeWhile, tap } from 'rxjs/operators';
|
||||
import { ApplicationException } from '../exceptions/application.exception';
|
||||
import { PubSubOptions } from './interfaces/pub-sub-options.interface';
|
||||
import {
|
||||
@ -22,6 +22,10 @@ export class PubSub extends EventEmitter {
|
||||
this.pubRedis = new IORedis(this.options.redis);
|
||||
this.pSubRedis = new IORedis(this.options.redis);
|
||||
|
||||
this.pSubRedis.on('pmessage', (...args) =>
|
||||
log.extend('raw')('%s %s %o', ...args),
|
||||
);
|
||||
|
||||
this.event$ = fromEvent<[string, string, string]>(
|
||||
this.pSubRedis,
|
||||
'pmessage',
|
||||
@ -37,6 +41,7 @@ export class PubSub extends EventEmitter {
|
||||
return ev;
|
||||
}),
|
||||
filter((v) => !!v),
|
||||
share(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -88,7 +93,7 @@ export class PubSub extends EventEmitter {
|
||||
filter(([pattern]) => pattern === channel),
|
||||
tap(([pattern, channel, message]) => {
|
||||
log.extend('subscribe')(
|
||||
'channel: %s, match: %, message: %O',
|
||||
'channel: %s, match: %s, message: %O',
|
||||
channel,
|
||||
pattern,
|
||||
message,
|
||||
|
Reference in New Issue
Block a user