Closed itrash0505 closed 2 years ago
Which version of the library are you using?
ng2-stompjs@8.0.0
"@angular/cli": "12.1.0",
"@angular/compiler-cli": "12.1.0",
"@stomp/ng2-stompjs": "8.0.0",
"jest": "^27.0.1",
This error, usually, happens if the underlying library was compiled to an ES version that did not support classes. The ng2-stompjs
package is bundled by a very old version of https://github.com/ng-packagr/ng-packagr to support Angular 6+. Unfortunately that causes issues in a few combinations in newer setups. The way to solve this issue fundamentally is to use newer tool chain to build ng2-stompjs
, however, that causes this library to fail with older Angular versions.
To minimize the impact, few years back, I extracted majority of the functionality to another package @stomp/rx-stomp
. At this stage the @stomp/ng2-stompjs
became a very thin Angular specific wrapper, for example https://github.com/stomp-js/ng2-stompjs/blob/develop/src/app/rx-stomp.service.ts
In your case you are not injecting the RxStompService
class, so, without any loss of functionality, you should be able to use @stomp/rx-stomp
. See if you can do that and whether that resolves the issue.
i am using RPC , replacing the library will work ?
const rxStompRPC = new RxStompRPC(this.rxStomp),
correlationId = utils.getCorellationId();
const resp = await rxStompRPC
.rpc({
destination: config.mq,
body: JSON.stringify(command),
headers: {
'correlation-id': correlationId,
exclusive: 'false',
'auto-delete': 'true',
},
})
.toPromise()
.then((x) => x),
respCorrelationId = resp.headers['correlation-id'];
if (respCorrelationId === correlationId) {
return JSON.parse(resp.body).data;
}
The above should work.
The library generates and matches the correlationId
, so, your code can be much simpler. Please check the guide at https://stomp-js.github.io/guide/rx-stomp/ng2-stompjs/remote-procedure-call.html
I am now using the@stomp/rx-stomp
library, and able to create the instances in the unit test.
I have one more question, is there any library which i can use to mockup the data response against the rpc request