How to propagate Exceptions in rpc nameko between two services


#1

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.


#2

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

···

On Wednesday, April 18, 2018 at 5:28:58 AM UTC+1, Chau Tran Anh Minh wrote:

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.


#3

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

···

On Wednesday, April 18, 2018 at 1:19:35 PM UTC+7, Jakub Borys wrote:

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

On Wednesday, April 18, 2018 at 5:28:58 AM UTC+1, Chau Tran Anh Minh wrote:

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.


#4

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

···

On Wednesday, April 18, 2018 at 8:04:03 AM UTC+1, Chau Tran Anh Minh wrote:

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

On Wednesday, April 18, 2018 at 1:19:35 PM UTC+7, Jakub Borys wrote:

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

On Wednesday, April 18, 2018 at 5:28:58 AM UTC+1, Chau Tran Anh Minh >> wrote:

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.


#5

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

···

On Wednesday, April 18, 2018 at 2:09:26 PM UTC+7, Jakub Borys wrote:

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

On Wednesday, April 18, 2018 at 8:04:03 AM UTC+1, Chau Tran Anh Minh wrote:

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