I have two project with nodejs and typescript and a want to start comunication with rabitmq .
i install amqplib
library from npm and use this config for published and subscriber project :
import amqp from ‘amqplib’;
export class MessageBroker {
private static channel: amqp.Channel;
public static async Initial(exchange: string, queue: string) {
let cluster = await amqp.connect('amqps://mcbzjnsn:[email protected]/mcbzjnsn');
let channel = await cluster.createChannel();
await channel.assertExchange(exchange, 'direct', { durable: true, autoDelete: true });
await channel.assertQueue(queue + '.' + exchange, {
exclusive: true
});
await channel.bindQueue(queue + '.' + exchange, exchange, queue);
channel.prefetch(1);
this.channel = channel;
}
//Random id generator
private static randomid() {
return new Date().getTime().toString() + Math.random().toString() + Math.random().toString();
}
static async Publish(exchange: string, queue: string, message: any): Promise<void> {
let id = this.randomid();
MessageBroker.channel.sendToQueue(exchange, queue,
Buffer.from(JSON.stringify(message)), { correlationId: id, replyTo: 'amq.rabbitmq.reply-to' })
}
static async SendToQueue(queue: string, message: any): Promise<void> {
let id = this.randomid();
MessageBroker.channel.sendToQueue(queue, Buffer.from('10'), {
correlationId: id,
replyTo: queue
});
}
private static async Consume(exchange: string, queue: string): Promise<void> {
}
}
now i want to use send message from project A to Project B with this code :
await MessageBroker.Publish('coin', 'transaction',{
type:MessageBrokerType.Transfer,
to:'0x36f5C37B48c7888634b9285ae30eeACa5AD427C0',
amount:100
});
and I need wait to projectB response but it does not wait for response from projectB and go the next line.
now, how can I do it? ( wait for response from the result of project B )