Unable to handle exception while endpoint is unreachable

Hi Everyone,

In our project we have the following pattern:

Controller API (Sending command to Endpoint1)

—> End point 1
{ //Handler
try
{
Logic 1
Send command to Endpoint2
Logic 2
}
catch(Exception ex)
{
throw ex;
}
}
—> End point 2 (Currently Unrechable)

1). We are sending command from controller to Endpoint1.
2). Command will be handled by a particular handler at endpoint1.
3). Now we are trying to sending other command to Endpoint2 (From inside same Handler of endpoint1)
4). Currently Endpoint2 is unreachable
5). Problem: We are unable to get/catch any information/exception, due to this the handler call is stuck in retry loop and all the logic are being executing again and again.

I’ve been searching for something to help point us in the right direction on how we can handle such kind of scenario in .net core application.

Hi @hirennservicebus,

Welcome to the Particular discussion group. I’m not sure I fully understand the scenario you are describing:

From an endpoint, there is no way to know what’s happening in another endpoint, and that’s a good thing, it reduces coupling. That being said, when endpoint 1 sends the command to endpoint 2 the message is dispatched to the queueing system and from there it’s managed by the broker/queues you are using.
If endpoint 2 is unavailable the message will sit in the endpoint 2 input queue waiting to be processed. If endpoint 2 fails to process it’ll be retried a few times (more info) before eventually being moved to the error queue.

.m

As to add to what Mauro shared.

You state:

Logic 1
Send command
Logic 2

Since NServiceBus 6 messages are not send immediately but batched. If Logic 2 fails, the message will not get send and retrying the message will return in Logic 1 to be executed again.

See Batched message dispatch • NServiceBus • Particular Docs for more info on batched dispatch

If Logic 1 and Logic 2 are independent tasks I would suggest to do:

Logic 1
Send command to endpoint 1
Send commend to self that will execute logic 2

This way Logic 2 will executed in isolation. If that fails Logic 1 will not be executed again.

If you want to keep your code as is but always send a messages you can use immediate dispatch as documented at Sending messages • NServiceBus • Particular Docs