How to propagate Exceptions in rpc nameko between two services

45 views
Skip to first unread message

Chau Tran Anh Minh

unread,
Apr 18, 2018, 12:28:58 AM4/18/18
to nameko-dev
Firstly, thanks very much for your effort in building nameko for microservices. Especially, nameko-examples is really a great asset to me. 

My project is mainly based on the example. However, I'm having some troubles in propagating Exceptions from internal services back to Gateway service when using a service to call event_dispatcher to another service. 

In my case, a method of "orders" call event_dispatch to "products", and then when a method of "products" throws an Exception (under event_handler decorator), how can the method of "orders" catch the exception and propagate back to Gateway service? I tried some params (options) in event_handler such set requeue_on_error = True but it does not work. Anyone can help me please? Thanks in advance. 

Jakub Borys

unread,
Apr 18, 2018, 2:19:35 AM4/18/18
to nameko-dev
Hi,

Glad to hear you're enjoying examples. 

Conceptually, events that are dispatched by a service can be handled by many different services and success/failure of their processing is not a concern of the service that dispatched the original event. 

In nameko we have 3 distinct messaging patterns:
1. Request/Response with RPC or HTTP. 
2. Dispatching Events, send by one service and handled by unknown amount of other services (fire and forget)
3. Publishing Messages, send by from one service explicitly to be handled by another but in fire and forget manner without waiting for the response.

Only first Request/Response pattern lands itself to where service originating the message can handle outcome of the downstream service processing. Handling of this exception between services is demonstrated in examples with remote_error pattern here: https://github.com/nameko/nameko-examples/blob/master/gateway/gateway/exceptions.py#L18

Otherwise if you're looking just to retry the event processing, you can use nameko-amqp-retry library that provides you with capability to retry on any entrypoint https://github.com/nameko/nameko-amqp-retry

Cheers,
Jakub

Chau Tran Anh Minh

unread,
Apr 18, 2018, 3:04:03 AM4/18/18
to nameko-dev
Dear Jakub,

Thanks very much for your quick response. The problem is I'm using number 2 and I would like to handle Exceptions from received services in original services. Can you please give me some hints to do that? Should I add a rpc or http decorator (number 1) on top of the event_handler decorator in requested services to handle this case? Again thanks very much for your helps.

Best Regards,
Chau

Jakub Borys

unread,
Apr 18, 2018, 3:09:26 AM4/18/18
to nameko-dev
Hi Chau,

You're correct, if you add an rpc decorator on top of your method you'll be able to call it synchronously and catch the error in originating service. 

Jakub

Chau Tran Anh Minh

unread,
Apr 18, 2018, 4:06:23 AM4/18/18
to nameko-dev
Dear Jakub,

Finally, I switch my flow to number 1 to handle Exception propagation. Tried to put Number 1 on top of number 2 decorator but it does not work. By the way, thanks very much for your helps.

Best regards 
Chau 
Reply all
Reply to author
Forward
0 new messages