so i want to take a Json and parse it to Object and then implement a RPC RabbitMQ Server so that i can send the Object to the Server through RabbitMQ and there the Object will be proceed to be saved in a local Array and a universally unique id which will tell where exactly is the object stored, will be returned from that Server to the client throught the RPC.
the Official Webseite shows some Implementation to RPC in RabbitMQ, here you can find their Implementration https://www.rabbitmq.com/tutorials/tutorial-six-javascript.html , in the Tutorial they send a Number and the Server will calculate Fibonacci Sequence and return the Result to the Client. instead i want to send an Object, not a Number and i want to receive the universally unique id(uuid) of that Object which i ll store in a global Array in my Program, i changed the code so that it ll send an Object and return the uuid but it didnt work. i ll apreciate any help from you guys
//this is my server_rpc.js code :
const amqp = require('amqplib/callback_api');
const uuid = require("uuid/v1");
amqp.connect('here is the url: example: localhost', (err, conn) => {
conn.createChannel( (err, ch) => {
let q = 'rpc_queue';
ch.assertQueue(q, {durable: false});
ch.prefetch(10);
console.log(' [x] Waiting RPC requests');
ch.consume(q, function reply(msg) {
console.log("corralation key is: ", msg.properties.correlationId);
let n = uuid();
console.log(" data received ",JSON.parse(JSON.stringify(msg.content.toString())));
console.log("corralation key is: ", msg.properties.correlationId);
ch.sendToQueue(msg.properties.replyTo, Buffer.from(n.toString()), {correlationId: msg.properties.correlationId});
ch.ack(msg);
});
});
});
// and this is my client_rpc.js code :
const amqp = require('amqplib/callback_api');
const uuid = require("uuid/v1");
const express = require("express");
let data = {
"name" : "hil01",
"region" : "weissach",
"ID" : "1",
"version" : "0.0.1"
}
amqp.connect('url: example localhost ', (err, conn) => {
conn.createChannel( (err, ch) => {
ch.assertQueue('', {exclusive: true}, (err, q) => {
var corr = generateUuid();
var newHil = JSON.stringify(data);
console.log(" [x] Requesting uuid for the registered HIL: ", newHil );
console.log("corralation key is: ", corr);
ch.consume(q.queue, function(msg) {
if(msg.properties.correlationId == corr) {
console.log(" [.] Got %s", msg.content.toString());
setTimeout(() => { conn.close(); process.exit(0) }, 100);
}
}, {noAck: true});
ch.sendToQueue('rpc_queue', Buffer.from(newHil, {correlationId: corr, replyTo: q.queue }));
});
});
});
//method to generate the uuid, later will be replaced with the real
uuid function
var generateUuid = () => Math.random().toString() +
Math.random().toString() + Math.random().toString() ;
when i run server_rpc, [x] waiting for requests should be printed then in a seperate cmd i run client_rpc.js then the object should be sent and the server execute and return to me the uuid back to the client.