public Task <TResult> Ask(TCriterion criterion) { var connection = _connectionFactory.Get <QueryNatsAdapter>(); QueryNatsAdapter response; try { response = (QueryNatsAdapter)connection.Request( _queueFactory.GetQueryQueue(criterion, typeof(TResult)), new QueryNatsAdapter(criterion, typeof(TResult)), 60000); } catch (NATSTimeoutException) { throw new Exception("Nats connection timeout exceed"); } var resultType = _typeFactory.Get(response.QueryResultType); if (resultType == typeof(TResult)) { return(Task.Run(() => _serializer.DeserializeMsg <TResult>(response.QueryResult, resultType))); } throw new Exception(response.QueryResult); }
public List <BkGame> Get(BkMqMessage message) { var msgType = _typeFactory.Get(message.MsgType); if (msgType == null) { return(null); } return(_serializer.DeserializeMsg <List <BkGame> >(message.Msg, msgType)); }
public IMessage GetCommand() { try { return(_serializer.DeserializeMsg <IMessage>(Command, CmdType)); } catch (Exception ex) { throw new InternalException( $"Error when deserializing {ToString()}", ex); } }
public ICriterion GetCriterion() { try { return(_serializer.DeserializeMsg <ICriterion>(Criterion, CriterionType)); } catch (Exception ex) { throw new InternalException( $"Error when deserializing {ToString()}", ex); } }
public async Task <TResult> Ask(TCriterion criterion) { var connection = _connectionFactory.Get <QueryNatsAdapter>(); var replySubj = GetRandomString(); QueryNatsAdapter response; try { var queryQueue = _queueFactory.Get(); var data = new QueryNatsAdapter(criterion, typeof(TResult)) { QueryResult = replySubj }; connection.Publish(queryQueue, data); connection.Flush(); response = await GetResponse(connection, replySubj, out var subscription); subscription.Dispose(); } catch (NATSTimeoutException) { throw new InternalException("Nats connection timeout exceed"); } catch (Exception ex) { throw new InternalException(ex.Message); } var resultType = _typeFactory.Get(response.QueryResultType); if (resultType == typeof(TResult)) { return(_serializer.DeserializeMsg <TResult>(response.QueryResult, resultType)); } throw new InternalException(response.QueryResult); }