1

I am using webstomp to comunicate with my message broker (In this case rabbit).

When I want to write a message I do the following:

import * as SockJS from 'sockjs-client';
let client = Stomp.over(new SockJS(serverAddress));
client.connect(user, pass, onConnect, onError);
client.send('/exchange/amq.direct/test', {test: 'one', test2: 'two'});

This message is received correctly by Rabbit but I would like to have a way to confirm that more than viasually. Something similar to:

client.send('/exchange/amq.direct/test', {test: 'one', test2: 'two'})
.then(() => {console.log('Message received correctly')})
.catch((err) => {console.log('Imposible send the message')})

Is there a way to do this?

Michael Szczesny
  • 4,911
  • 5
  • 15
  • 32
GutiMac
  • 2,402
  • 1
  • 20
  • 27

1 Answers1

1

Messages can be transferred reliably from publishers to the broker. (using transactions or confirms). Messages can also be transferred reliably from the broker to consumers. (using acknowledgements) Taken together this provides reliable transfer from publishers to consumers.

So in this case I should add this header:

{persistent: true}

Or use a transaction as:

// start the transaction
var tx = client.begin();
// send the message in a transaction
client.send("/queue/test", {transaction: tx.id}, "message in a transaction");
// commit the transaction to effectively send the message
tx.commit();
GutiMac
  • 2,402
  • 1
  • 20
  • 27