Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit f069d93

Browse files
sam0r040timonback
authored andcommitted
feat: Add headers to published events
Co-authored-by: Timon Back <timonback@users.noreply.github.com>
1 parent bca8b81 commit f069d93

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/app/channels/channel-main/channel-main.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h4>{{ operation.message.description }}</h4>
1414
(keyup)="recalculateLineCount('example', exampleTextArea.value)"
1515
></textarea>
1616
<div fxLayout fxLayoutGap="8px">
17-
<button mat-raised-button color="primary" (click)="publish(exampleTextArea.value)">
17+
<button mat-raised-button color="primary" (click)="publish(exampleTextArea.value, headersTextArea.value)">
1818
Publish
1919
</button>
2020
<button mat-raised-button color="primary"

src/app/channels/channel-main/channel-main.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ export class ChannelMainComponent implements OnInit {
6666
}
6767
}
6868

69-
publish(example: string): void {
69+
publish(example: string, headers: string): void {
7070
try {
71-
const json = JSON.parse(example);
71+
const payloadJson = JSON.parse(example);
72+
const headersJson = JSON.parse(headers)
7273

73-
this.publisherService.publish(this.protocolName, this.channelName, json).subscribe(
74+
this.publisherService.publish(this.protocolName, this.channelName, payloadJson, headersJson).subscribe(
7475
_ => this.handlePublishSuccess(),
7576
err => this.handlePublishError(err)
7677
);

src/app/shared/publisher.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export class PublisherService {
88

99
constructor(private http: HttpClient) { }
1010

11-
publish(protocol: string, topic: string, payload: object): Observable<unknown> {
11+
publish(protocol: string, topic: string, payload: object, headers: object): Observable<unknown> {
1212
const url = Endpoints.getPublishEndpoint(protocol);
1313
const params = new HttpParams().set('topic', topic);
14+
const body = {"payload" : payload, "headers" : headers }
1415
console.log(`Publishing to ${url}`);
15-
return this.http.post(url, payload, { params });
16+
return this.http.post(url, body, { params });
1617
}
1718

1819
}

0 commit comments

Comments
 (0)