예제 #1
0
 public static void Handle(XTask task)
 {
     var ms = (DateTime.UtcNow - task.Timestamp).TotalMilliseconds;
     Log.Info($"Got {task.Name} Latency: {ms} ms.");
     Meter.Mark();
     Histogram.Update((long) ms);
 }
예제 #2
0
        public static XTask[] GenerateTasks(int count)
        {
            var tasks = new XTask[count];
            for (int i = 0; i < count; i++)
            {
                var description = new char[TaskSize];
                for (int j = 0; j < TaskSize; j++)
                    description[j] = Alphabet[Random.Next(Alphabet.Length)];
                
                tasks[i] = new XTask
                {
                    Description = new string(description)
                };

                lock (TaskNumberLock)
                {
                    tasks[i].Name = $"Task #{TaskNumber++}";
                }
            }
            
            for (int i = 0; i < count; i++)
                tasks[i].Timestamp = DateTime.UtcNow;

            return tasks;
        }
예제 #3
0
        public static void Publish(XTask[] tasks)
        {
            Thread.Sleep(10);
            var contentType = "application/vnd.kafka.json.v1+json";
            var accept = "application/vnd.kafka.v1+json, application/vnd.kafka+json, application/json";
            var data = JsonConvert.SerializeObject(new { records = tasks.Select(x => new { value = x }) });

            try
            {
                WebRequestHelper.Post(Config.HostName, $"topics/{Config.TopicName}", data, contentType, accept);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
            }
        }