private async Task CreateService(SqlConnection cn, SqlTransaction tx, string name, string queueName, string contractName)
        {
            var cmdtext  = @"select name from sys.services where name=@name";
            var existing = await _sqlCommandExecutor.ExecuteScalarAsync <string>(cn, tx, cmdtext, new SqlParameter("@name", name));

            if (!string.IsNullOrEmpty(existing))
            {
                return;
            }

            await _sqlCommandExecutor.ExecuteCommandAsync(cn, tx, $"CREATE SERVICE [{name}] ON QUEUE [{queueName}]([{contractName}]);");
        }
Пример #2
0
        /// <inheritdoc />
        /// <summary>
        /// Get an id from the specified queue.
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns>Next id from queue, null if no message arrives in one second.</returns>
        public async Task <string> DequeueWork(QueueType queue, CancellationToken cancellationToken)
        {
            SqlConnection cn = new SqlConnection(_connectionString);

            try
            {
                await cn.OpenAsync(cancellationToken);

                var par = _config.GetByQueue(queue);
                var sql = _dequeueWorkCommand.Replace("{queueName}", par.QueueName);
                var msg = await _sqlCommandExecutor.ExecuteScalarAsync <object>(cn, null, sql);

                return(msg is DBNull ? null : (string)msg);
            }
            finally
            {
                cn.Close();
            }
        }