コード例 #1
0
        public ProducerResult Send(int key, string message)
        {
            using (var producer = new Producer <int, string>(GetConfig(), new IntSerializer(), new StringSerializer(Encoding.UTF8)))
            {
                var ret = producer.ProduceAsync(ConfigHelper.Configuration.GetValue <string>("Karafka:topicName"), key, message).Result;

                if (ret.Error.HasError)
                {
                    return(ProducerResult.GetError($"Error Code:{ret.Error.Code} Reason: {ret.Error.Reason}"));
                }

                producer.Flush(TimeSpan.FromSeconds(10));
            }

            return(ProducerResult.Sucess);
        }