Esempio n. 1
0
        private static async void Produce()
        {
            IConfluentClient client = new ConfluentClient(new MyConfluentClientSettings());

            var records = new[]
            {
                new AvroRecord<string, Person>
                {
                    PartitionId = Convert.ToInt32(0),
                    Value = new Person { Name = Guid.NewGuid().ToString("N"), Age = 25 }
                },
                new AvroRecord<string, Person>
                {
                    Value = new Person { Name = Guid.NewGuid().ToString("N"), Age = 26 }
                }
            };

            var recordSet = new AvroRecordSet<string, Person>(records)
            {
                //Creating schema using "Microsoft.Hadoop.Avro" - https://www.nuget.org/packages/Microsoft.Hadoop.Avro/
                ValueSchema = AvroSerializer.Create<Person>().ReaderSchema.ToString()
            };

            await client.PublishAsAvroAsync("TestTopic", recordSet);
        }
Esempio n. 2
0
 public async Task <ConfluentResponse <PublishResponse> > PublishAsAvroAsync <TKey, TValue>(
     string topic,
     AvroRecordSet <TKey, TValue> recordSet)
     where TKey : class
     where TValue : class
 {
     return(await PublishAsAvroAsync(topic, recordSet, CancellationToken.None).ConfigureAwait(false));
 }
Esempio n. 3
0
        public async Task <ConfluentResponse <PublishResponse> > PublishAsAvroAsync <TKey, TValue>(
            string topic,
            AvroRecordSet <TKey, TValue> recordSet, CancellationToken cancellationToken)
            where TKey : class
            where TValue : class
        {
            string requestUri = string.Format("/topics/{0}", topic);

            HttpRequestMessage request = CreateRequestMessage(HttpMethod.Post, requestUri)
                                         .WithContent(recordSet, ContentTypeKafkaAvro);

            return(await ProcessRequest <PublishResponse>(request, cancellationToken).ConfigureAwait(false));
        }
Esempio n. 4
0
        private void buttonAvro_Click(object sender, EventArgs e)
        {
            Run(() =>
            {
                var records = new[]
                {
                    new AvroRecord <string, Person>
                    {
                        PartitionId = GetPartitionId(),
                        Value       = GetPerson()
                    },
                    new AvroRecord <string, Person>
                    {
                        Value = GetPerson()
                    }
                };
                var recordSet = new AvroRecordSet <string, Person>(records)
                {
                    ValueSchema = AvroSerializer.Create <Person>().ReaderSchema.ToString()
                };

                return(_confluentClient.PublishAsAvroAsync(textBoxTopic.Text, recordSet).Result);
            });
        }