private async Task <(bool IsCreated, BongoSimpleClient Client)> TryCreateClient(IPEndPoint host) { BongoSimpleClient client = null; try { client = new BongoSimpleClient(host); await client.Query("show databases;"); return(true, client); } catch (Exception e) { client?.Dispose(); Context .GetLogger() .Warning("Could not start bongo client.. will retry"); return(false, null); } }
private void ConnectionLeased( IPEndPoint host, IActorRef router, BongoSimpleClient client, IConnectionLease lease) { Receive <ConnectionLeaseRelease>(release => { if (release.Lease != lease) { return; } Become(() => WaitForLease(host, router, client)); Stash.UnstashAll(); }); ReceiveAsync <LeaseQuery>(async query => { if (query.ConnectionLeaseId != lease.ConnectionLeaseId) { Sender.Tell(new LeaseRejection()); return; } try { var response = await client.Query(query.Query); Sender.Tell(response); } catch (BeeswaxException e) { Sender.Tell(e); } catch (Exception e) { Context.GetLogger().Error(e, "Error in connection"); Sender.Tell(e); router.Tell(new RemoveRoutee(_routee)); Become(() => InitializeConnection(host, router)); Stash.UnstashAll(); } }); ReceiveAsync <LeaseInsert>(async query => { if (query.ConnectionLeaseId != lease.ConnectionLeaseId) { Sender.Tell(new LeaseRejection()); return; } try { await client.Insert(query.Insert); Sender.Tell(new LeaseInsertSuccess()); } catch (BeeswaxException e) { Sender.Tell(e); } catch (Exception e) { Context.GetLogger().Error(e, "Error in connection"); Sender.Tell(e); router.Tell(new RemoveRoutee(_routee)); Become(() => InitializeConnection(host, router)); Stash.UnstashAll(); } }); ReceiveAny(_ => Stash.Stash()); Sender.Tell(lease); }