stomp-js / rx-stomp

STOMP adaptor for RxJS
Apache License 2.0
111 stars 21 forks source link

watchForReceipt throws an error if the client is not connected #484

Closed akaNightmare closed 1 year ago

akaNightmare commented 1 year ago

Hello.

async function test(receipt) {
  rxClient.publish({
    // other params
    headers: { receipt },
  });
  return new Promise(resolve => rxClient.watchForReceipt(receipt, resolve));
}

throws an error TypeError: Cannot read property 'watchForReceipt' of undefined of the client is not connected

Thanks.

kum-deepak commented 1 year ago

To be fixed in the next release.

akaNightmare commented 1 year ago

@kum-deepak any updates?

kum-deepak commented 1 year ago

I realized there is another way to watch for receipts, which works better with RxStomp and does not suffer from the issue you reported.

Two changes:

  const promiseReceipt = (receiptId: string) =>
    firstValueFrom(
      rxStomp.unhandledReceipts$.pipe(
        filter(frame => frame.headers['receipt-id'] === receiptId)
      )
    );
// ....
    // Now publish to the same queue with the receipt request
    const publishReceipt = 'publish-receipt';
    const promisePublishReceipt = promiseReceipt(publishReceipt);
    rxStomp.publish({
      destination: queueName,
      body: msg,
      headers: { receipt: publishReceipt },
    });
    await promisePublishReceipt;

Try this out. Based on that, I will update the documentation.

akaNightmare commented 1 year ago

thanks. Let's keep it open until the issue will be fixed

kum-deepak commented 1 year ago

Did it work for you?

akaNightmare commented 1 year ago

this is working as expected, thank you.

kum-deepak commented 1 year ago

I just now released @stomp/rx-stomp@2.0.0-beta1. The newly added function is asyncReceipt

kum-deepak commented 1 year ago

Released v2.0.0