Referring to Akka.Net documentation, using PipeTo()
is preferred when dealing with asynchronous jobs.
When dealing with a function that returns Task<T>
, I can handle the failure event, no problem.
The problem is, when dealing with a function that does not return any type, but only Task
, one still calls the PipeTo
function, but instead of having the overload which contains the failure handle, it now says the following: 'As this task has no result, only exceptions will be piped to the recipient.'.
Does this mean, if I have the following code:
public class RepositoryComponent : IRepositoryComponent
{
private SqlSettings _sqlSettings;
public RepositoryComponent(SqlSettings sqlSettings)
{
_sqlSettings = sqlSettings;
}
public async Task InsertJobAsync(RetryModel job)
{
try
{
await... //some logic
}
catch { throw; }
}
}
My actor:
public class RepositoryActor : ActorBase
{
private IRepositoryComponent _repoComponent;
private ActorSelection _retryActor;
public RepositoryActor(IRepositoryComponent repoComponent) : base()
{
_repoComponent = repoComponent;
}
public override void Listening()
{
Receive<RepositoryMessages.GenericRequestNoReturn>(x => InvokeRequest(x));
Receive<RepositoryMessages.GenericRequestWithResponseType>(x => InvokeRequestAndSendResponse(x));
}
private void InvokeRequest(RepositoryMessages.GenericRequestNoReturn msg)
{
try
{
//some logic with msg
_repoComponent.InsertJobAsync(new Core.Models.RetryModel()).PipeTo(Context.Self);
}
catch (Exception ex)
{
base.ExceptionHandling(ex);
}
}
}
In order to catch exceptions in the above actor, I need to add another Receive handler to cater for exceptions, as for example, below:
Receive<Exception>(x => SomeExceptionHandler(x));
Is this correct? If so, no need for the try {} catch {}
around my code block?