Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 공용 메시지 브로커 구현 및 적용 #16

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cb9e499
feat: 메시지큐 구현
codemario318 Jan 21, 2025
316d744
feat: message-queue 모듈 등록
codemario318 Jan 22, 2025
5128b99
fix: 메시지큐 구현 제거
codemario318 Jan 22, 2025
8d058b4
feat: pub-sub 기능 구현
codemario318 Jan 22, 2025
dab1606
refactor: pub-sub 적용
codemario318 Jan 22, 2025
22284cc
fix: pub-sub 인터페이스 수정
codemario318 Jan 22, 2025
bb3efe4
feat: 메시지 브로커 수정
codemario318 Jan 22, 2025
69d6b1c
fix: 브로커 초기화 오류 수정
codemario318 Jan 22, 2025
36385ac
feat: 메시지 브로커 구현체 추가
codemario318 Jan 22, 2025
95262f6
feat: ReactiveMessageBroker 적용
codemario318 Jan 22, 2025
e2b760d
fix: 채팅 핸들러 수정
codemario318 Jan 22, 2025
01d3048
refactor: play 영역 pub-sub 모듈 적용
codemario318 Jan 22, 2025
aab69ef
refactor: pub-sub 이름 변경
codemario318 Jan 23, 2025
fe899b2
refactor: Broker 구조 변경
codemario318 Jan 23, 2025
6ff1c2d
refactor: broker 변경 사항 반영
codemario318 Jan 23, 2025
d7306a0
refactor: chat 서비스 broker 리펙토링 반영
codemario318 Jan 23, 2025
1d1971c
refactor: broker 모듈 위치 변경
codemario318 Jan 23, 2025
75bf70c
refactor: 공용 broker 수정
codemario318 Jan 23, 2025
3244f1a
chore: shared 의존성 추가
codemario318 Jan 23, 2025
5153f07
refactor: broker 모듈 변경 반영
codemario318 Jan 23, 2025
b09a1f7
refactor: reactive-message-broker 수정
codemario318 Jan 23, 2025
68df88e
chore: shared 패키지 의존성 추가
codemario318 Jan 23, 2025
f07a735
refactor: play clients 의존성 제거
codemario318 Jan 23, 2025
6856587
fix: play gateway 기능 복구
codemario318 Jan 23, 2025
3dcca09
refactor: broker 인터페이스 변경
codemario318 Jan 24, 2025
4d609af
refactor: broker 인터페이스 변경
codemario318 Jan 24, 2025
144c424
refactor: pub/sub 모듈 수정
codemario318 Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: 메시지 브로커 구현체 추가
- RxJS를 활용한 메시지 브로커 구현
codemario318 committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 36385aca9d052a07f10cfe083c5d2a1cd85785a1
56 changes: 56 additions & 0 deletions apps/backend/src/core/pub-sub/reactive-message-broker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Subject } from 'rxjs';
import { Message } from './interfaces/message.interface';
import { PubSub } from './interfaces/pub-sub.interface';

export class ReactiveMessageBroker<TTopic, TData> implements PubSub<TTopic, TData> {
constructor(
private publishers: Map<string, Subject<Message<TTopic, TData>>> = new Map(),
) {}

public async addPublisher(id: string) {
if (this.publishers.has(id)) {
throw new Error(`Publisher with ID ${id} already exists`);
}

this.publishers.set(id, new Subject<Message<TTopic, TData>>());
}

public async removePublisher(id: string) {
const publisher = this.publishers.get(id);
if (!publisher) {
throw new Error(`Publisher with ID ${id} does not exist`);
}

publisher.complete();
this.publishers.delete(id);
}

public async publish(id: string, message: Message<TTopic, TData>) {
const publisher = this.publishers.get(id);

if (!publisher) {
throw new Error(`Publisher with ID ${id} does not exist`);
}

publisher.next(message);
}

public async subscribe(
publisherId: string,
subscriberId: string,
handler: (message: Message<TTopic, TData>) => void
) {
const publisher = this.publishers.get(publisherId);

if (!publisher) {
throw new Error(`Publisher with ID ${publisherId} does not exist`);
}

const subscription = publisher.subscribe({
next: handler,
error: (error) => console.error(`Error in subscription ${publisherId}:${subscriberId} :`, error)
});

return async () => subscription.unsubscribe();
}
}