i have two service and i created that with nodejs and typescript .
i want to send and recive message between these two services with reabitMQ .
i do it with this code :
Publisher :
await MessageBroker.Publish('coin', 'transaction', {
type: MessageBrokerType.Transfer,
to: 'to',
amount: amount
});
Consume :
MessageBroker.channel.consume(exchange + '.' + queue, async (msg: any) => {
const { to, amount , type } = JSON.parse(msg.content);
const transfer = await UnitOfWork.coinRepository.transfer(to, amount);
console.log(to, amount);
})
it's worked and send message from publisher to consume but i have a problem .
i need to set result for consume and send it for publisher .
for exmaple maybe i have a problem in this line UnitOfWork.coinRepository.transfer(to, amount); and i should send to publisher error message and if operation sucess send message to subscriber about success result .
now how can i solve this problem and set result for message between two service ?
What you have done so far is implementation of pub/sub with RabbitMQ and what you need to do is to setup a message-driven architecture (RPC).
This document clarifies what you need to do perfectly for an RPC pattern:
https://www.rabbitmq.com/tutorials/tutorial-six-javascript.html
The examples are written in Js but you can surely change them to Typescript.
Message-Driven will be handled by correlationId which is used to correlate RPC responses with requests, that's what you need to implement, more information can be found in the document. At the end of day if you weren't successful implementing it, ask me for a real sample with Typescript.