/// <summary> /// Handles the specified query. /// </summary> /// <param name="query">The query.</param> /// <returns></returns> public IReceivedMessageInternal Handle(ReceiveMessageQuery <IDbConnection, IDbTransaction> query) { if (!_databaseExists.Exists(_connectionInformation.ConnectionString)) { return(null); } using (var connection = _dbFactory.CreateConnection(_connectionInformation.ConnectionString, false)) { connection.Open(); using (var transaction = _dbFactory.CreateTransaction(connection).BeginTransaction()) { using (var selectCommand = connection.CreateCommand()) { selectCommand.Transaction = transaction; CommandString commandString = GetDeQueueCommand(_tableNameHelper.MetaDataName, _tableNameHelper.QueueName, _tableNameHelper.StatusName, query.Routes); _buildDequeueCommand.BuildCommand(selectCommand, commandString, _options.Value, query.Routes); using (var reader = selectCommand.ExecuteReader()) { return(_messageDeQueue.HandleMessage(connection, transaction, reader, commandString)); } } } } }
/// <summary> /// Handles the specified query. /// </summary> /// <param name="query">The query.</param> /// <returns></returns> /// <exception cref="PoisonMessageException">An error has occured trying to re-assemble a message de-queued from SQLite</exception> /// <exception cref="MessageQueueId"></exception> public async Task <IReceivedMessageInternal> Handle(ReceiveMessageQueryAsync <IDbConnection, IDbTransaction> query) { if (!_databaseExists.Exists(_connectionInformation.ConnectionString)) { return(null); } using (var connection = _dbFactory.CreateConnection(_connectionInformation.ConnectionString, false)) { connection.Open(); using (var transaction = _dbFactory.CreateTransaction(connection).BeginTransaction()) { using (var selectCommand = connection.CreateCommand()) { selectCommand.Transaction = transaction; CommandString commandString = GetDeQueueCommand(_tableNameHelper.MetaDataName, _tableNameHelper.QueueName, _tableNameHelper.StatusName, query.Routes); if (commandString == null) { throw new DotNetWorkQueueException("Failed to generate command text for de-queue of messages"); } _buildDequeueCommand.BuildCommand(selectCommand, commandString, _options.Value, query.Routes); using (var reader = await _readerAsync.ExecuteReaderAsync(selectCommand).ConfigureAwait(false)) { return(_messageDeQueue.HandleMessage(connection, transaction, reader, commandString)); } } } } }