question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RPC not working: What I am doing wrong? Is there an example of its implementation?

See original GitHub issue

Greetings,

Will you help me?

I apologize to bother but I am having troubles implementing RPC correctly.

Perhaps someone can point out what I am doing wrong in the code since I couldn’t find in the documentation a full example on how to implemented.

// Publish RPC from this client to server
var extension = {
 id: UUID.random(),
}

var body = {...};

rabbit.publish('rpc.extension.request', {
    routingKey: 'extend.rpc',
    correlationId: extension.id,
    replyTo: "rpc.extension.response",
    contentType: "application/json",
    body: body,
    expiresAfter: 60000 // TTL in ms, in this example 60 seconds - can be removed after consumer working, just here to prevent junk accumulating on servers.
  }).then(
    () => { // a list of the messages of that succeeded
      log.info(`Success publishing extension for rpc ${extension.id}`);
    },
    (failed) => { // a list of failed messages and the errors `{ err, message }`
      log.info(`Error publishing extension for rpc ${extension.id} ->  ${failed.err}: ${failed.message}`);
    });

-----------------------
// Consuming RPC result sent by server to this client.

module.exports.setup = function () {
	...

	const handleRPC = rabbit.handle({queue: 'rpc.extension.response'}, handleExtendRPCResponse);
	handleRPC.catch(onHandleError);
};

function handleExtendRPCResponse(msg) {
	logger.info(`RPC Received message : ${msg}`)

	try {
		messageHandler.processMessage(msg, function (err) {
			if (err) {
				logger.error(`ERROR in RPC Process message: "${err.error}"`);
				msg.reject();
			} else {
				logger.info("Process RPC message passed");
				msg.ack();
			}
		})
	} catch(e){
		logger.error(`ERROR while Processing RPC message: "${e.message}"`);
		msg.reject();
	}
}

function onHandleError (err, msg) {
    // not able to hit this with a test...not sure how to.
    logger.error('Error:', JSON.stringify(err), 'Message:', JSON.stringify(msg));
    // Temporary, but if we can't handle it we don't want it requeued.
    msg.reject();
}

Thanks for your time and the creation of this package.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
acarlsteincommented, Feb 25, 2019

I figured out the issue. In the topology, when creating the exchange, I needed to add ‘subscribe:true’ property since the queue was already created but used as publish instead of request.

Thanks anyways for the feedback. I appreciate it.

0reactions
zlintzcommented, Mar 29, 2019

That makes sense why this problem seemed so familiar. I helped @fifthfloorsoftware with this back then

Read more comments on GitHub >

github_iconTop Results From Across the Web

RPC error troubleshooting guidance - Windows Client
Learn how to troubleshoot Remote Procedure Call (RPC) errors that occur during computer-to-computer communication.
Read more >
Tips To Handle RPC Request Errors - Chainstack Blog
We are sharing different solutions to handle RPC request errors in your application: promise methods, retries, and backup providers.
Read more >
REST vs. RPC: what problems are you trying to solve with ...
Calling a remote procedure is usually syntactically the same as calling a normal programming language procedure, and learning the procedures of ...
Read more >
Writing an RPC From Scratch - Caffeinspiration
This is where remote procedure calls come into play. We can wrap the complexity of inter-computer communication in the center, and we can ......
Read more >
Lecture 9: February 20 9.1 Failure Semantics - LASS
doesn't implement any error correction or handles packet losses in the network. ... For example, client made a RPC request, but before the....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found