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

feat: Add headers to published events #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/app/channels/channel-main/channel-main.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h4>{{ operation.message.description }}</h4>
(keyup)="recalculateLineCount('example', exampleTextArea.value)"
></textarea>
<div fxLayout fxLayoutGap="8px">
<button mat-raised-button color="primary" (click)="publish(exampleTextArea.value)">
<button mat-raised-button color="primary" (click)="publish(exampleTextArea.value, headersTextArea.value)">
Publish
</button>
<button mat-raised-button color="primary"
Expand Down
7 changes: 4 additions & 3 deletions src/app/channels/channel-main/channel-main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ export class ChannelMainComponent implements OnInit {
}
}

publish(example: string): void {
publish(example: string, headers: string): void {
try {
const json = JSON.parse(example);
const payloadJson = JSON.parse(example);
const headersJson = JSON.parse(headers)

this.publisherService.publish(this.protocolName, this.channelName, json).subscribe(
this.publisherService.publish(this.protocolName, this.channelName, payloadJson, headersJson).subscribe(
_ => this.handlePublishSuccess(),
err => this.handlePublishError(err)
);
Expand Down
5 changes: 3 additions & 2 deletions src/app/shared/publisher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export class PublisherService {

constructor(private http: HttpClient) { }

publish(protocol: string, topic: string, payload: object): Observable<unknown> {
publish(protocol: string, topic: string, payload: object, headers: object): Observable<unknown> {
const url = Endpoints.getPublishEndpoint(protocol);
const params = new HttpParams().set('topic', topic);
const body = {"payload" : payload, "headers" : headers }
console.log(`Publishing to ${url}`);
return this.http.post(url, payload, { params });
return this.http.post(url, body, { params });
}

}