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

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

            _sqlCommandExecutor.ExecuteCommand(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
            {
                cn.Open();
                var par = _config.GetByQueue(queue);
                var sql = _dequeueWorkCommand.Replace("{queueName}", par.QueueName);
                var msg = _sqlCommandExecutor.ExecuteScalar <object>(cn, null, sql);
                return(msg is DBNull ? null : (string)msg);
            }
            finally
            {
                cn.Close();
            }
        }