0

I have a MessageService component for the interaction between components wherever they are in the app, they just use the subscribe and sendMessage methods of injected MessageService.

When I load a page with A, B component messages can be exchanged, but as use another independent observable function (http.get of HttpClient request to load data) the MessageService subject subscribers decrease from 2 to 1. And A and B cant exchange messages.

My question is, how can I find out what's happening in the background?

UPDATED - BELOW

When the page load then no problem but after loading some data from the net. In A message fired but it doesnt arrive at B

A. (its container has injected MessageService, and accessed by "this")

<file-export [fileExportInput]="this" *ngIf="hasExport"></file-export>

@Input()
  fileExportInput: FileExportInputInterface;

  ngOnInit() {
    console.log("fileexport message service:", this.fileExportInput.messageService);
    this.fileExportInput.messageService ? this.message = true : this.message = false;
    if (this.message) {
      this.message$ = {
        next: (message: Message) => {
    ....    
     this.$subscription = this.fileExportInput.messageService.subscribe(this.message$);
    }
  }

B
constructor(private router: Router, private boeManagementService: BoeManagementService,
    private translateService: TranslateService, public messageService: MessageService) {
      console.log("boex message service:", this.messageService);
    /** file-export */
    this.message$ = {
      next: (message: Message) => {
        if (message.type === MessageType.FILE_EXPORT_ELEMENTS_REQUEST) { <---- CANT be reached this part
....
    this.$subscription = this.messageService.subscribe(this.message$);
  }

Thanks in advance,

Csaba

user647314
  • 323
  • 1
  • 4
  • 13
  • It would be easier to assist if you showed some code. Even easier if you could reproduce on [StackBlitz](https://www.stackblitz.com) :-) – BizzyBob Feb 10 '21 at 00:01
  • Im afraid it would work well - because it should not happen, I need some tip how can I debug this with console log or chrome dev tools, I see it goes from 2 to 1 subscription but i cant find more about it. – user647314 Feb 10 '21 at 00:05
  • Is there a public `messages$` observable on the service that components subscribe to?When you say "can't exchange messages" you mean A sends message and B doesn't receive it? – BizzyBob Feb 10 '21 at 00:08
  • Here comes the MessageService https://pastebin.com/hEisA36r, Q1: no, its private, Q2: yes – user647314 Feb 10 '21 at 00:15
  • Can you provide component code as well? Are either of the consuming components being controlled with `*ngIf`. Maybe the component is being destroyed causing the unsubscribe? Maybe second component is subscribing after message has been sent, thus looking like it's not receiving messages... – BizzyBob Feb 10 '21 at 02:17

1 Answers1

0

finally I could find out why the subscription was closed. The steps in Observer.next handler threw an exception, I could find out with Chrome devtools pause on exception feature in debug mode.

enter image description here

As I eliminated the cause of the exception everything works well.

user647314
  • 323
  • 1
  • 4
  • 13