Skip to content

Commit b2301d9

Browse files
committed
Make events compatible with rabbitMq event bus
1 parent fa86ca9 commit b2301d9

File tree

36 files changed

+235
-79
lines changed

36 files changed

+235
-79
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import config from '../../config';
2+
import RabbitMqConfig from '../../../../../Shared/infrastructure/EventBus/RabbitMq/RabbitMqConfig';
3+
4+
export class RabbitMqConfigFactory {
5+
static createConfig(): RabbitMqConfig {
6+
return {
7+
host: config.get('rabbitMQ.host'),
8+
user: config.get('rabbitMQ.user'),
9+
password: config.get('rabbitMQ.password'),
10+
queue: config.get('rabbitMQ.queue'),
11+
exchange: config.get('rabbitMQ.exchange')
12+
};
13+
}
14+
}
File renamed without changes.

src/Contexts/Backoffice/Courses/infrastructure/config/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ const backofficeConfig = convict({
1414
env: 'ELASTIC_URL',
1515
default: 'http://localhost:9200'
1616
}
17+
},
18+
rabbitMQ: {
19+
host: {
20+
doc: 'The RabbitMQ connection host',
21+
format: String,
22+
env: 'RABBITMQ_HOST',
23+
default: 'localhost'
24+
},
25+
user: {
26+
doc: 'The RabbitMQ connection user',
27+
format: String,
28+
env: 'RABBITMQ_DEFAULT_USER',
29+
default: 'guest'
30+
},
31+
password: {
32+
doc: 'The RabbitMQ connection password',
33+
format: String,
34+
env: 'RABBITMQ_DEFAULT_PASS',
35+
default: 'guest'
36+
},
37+
queue: {
38+
doc: 'Queue where subscribers listen on',
39+
format: String,
40+
env: 'RABBITMQ_QUEUE',
41+
default: 'BackofficeCourses-DomainEvents'
42+
},
43+
exchange: {
44+
doc: 'Exchange where events are published',
45+
format: String,
46+
env: 'RABBITMQ_EXCHANGE',
47+
default: 'DomainEvents'
48+
}
1749
}
1850
});
1951

src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type CreateCourseDomainEventBody = {
44
readonly duration: string;
55
readonly name: string;
66
readonly eventName: string;
7+
readonly id: string;
78
};
89

910
export class CourseCreatedDomainEvent extends DomainEvent {
@@ -31,11 +32,12 @@ export class CourseCreatedDomainEvent extends DomainEvent {
3132
}
3233

3334
toPrimitive(): CreateCourseDomainEventBody {
34-
const { name, duration } = this;
35+
const { name, duration, aggregateId } = this;
3536
return {
3637
name,
3738
duration,
38-
eventName: CourseCreatedDomainEvent.EVENT_NAME
39+
eventName: CourseCreatedDomainEvent.EVENT_NAME,
40+
id: aggregateId
3941
};
4042
}
4143

src/Contexts/Mooc/CoursesCounter/domain/CoursesCounterIncrementedDomainEvent.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ export class CoursesCounterIncrementedDomainEvent extends DomainEvent {
1111

1212
toPrimitive(): Object {
1313
return {
14-
total: this.total
14+
total: this.total,
15+
eventName: CoursesCounterIncrementedDomainEvent.EVENT_NAME
1516
};
1617
}
1718

18-
static fromPrimitive(
19+
static fromPrimitives(
1920
aggregateId: string,
2021
body: { total: number },
2122
eventId: string,

src/Contexts/Mooc/Notifications/domain/UserRegisteredDomainEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class UserRegisteredDomainEvent extends DomainEvent {
1313
}
1414

1515
toPrimitive(): Object {
16-
return { userEmailAddress: this.userEmailAddress };
16+
return { userEmailAddress: this.userEmailAddress, eventName: UserRegisteredDomainEvent.EVENT_NAME };
1717
}
1818

1919
static fromPrimitives(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import config from '../../config';
2+
import RabbitMqConfig from '../../../../../Shared/infrastructure/EventBus/RabbitMq/RabbitMqConfig';
3+
4+
export class RabbitMqConfigFactory {
5+
static createConfig(): RabbitMqConfig {
6+
return {
7+
host: config.get('rabbitMQ.host'),
8+
user: config.get('rabbitMQ.user'),
9+
password: config.get('rabbitMQ.password'),
10+
queue: config.get('rabbitMQ.queue'),
11+
exchange: config.get('rabbitMQ.exchange')
12+
};
13+
}
14+
}

src/Contexts/Mooc/Shared/infrastructure/config/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ const moocConfig = convict({
3333
format: String,
3434
env: 'RABBITMQ_DEFAULT_PASS',
3535
default: 'guest'
36+
},
37+
queue: {
38+
doc: 'Queue where subscribers listen on',
39+
format: String,
40+
env: 'RABBITMQ_QUEUE',
41+
default: 'Mooc-DomainEvents'
42+
},
43+
exchange: {
44+
doc: 'Exchange where events are published',
45+
format: String,
46+
env: 'RABBITMQ_EXCHANGE',
47+
default: 'DomainEvents'
3648
}
3749
}
3850
});

src/Contexts/Retention/Campaign/domain/UserRegisteredDomainEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class UserRegisteredDomainEvent extends DomainEvent {
1313
}
1414

1515
toPrimitive(): Object {
16-
return { userEmailAddress: this.userEmailAddress };
16+
return { userEmailAddress: this.userEmailAddress, eventName: UserRegisteredDomainEvent.EVENT_NAME };
1717
}
1818

1919
static fromPrimitives(
6 KB
Binary file not shown.

0 commit comments

Comments
 (0)