private void PlainKeyValueProducer(string topic) { //var jsonSchem = AvroSchema<JournalEntry>.Of(typeof(JournalEntry)); var jsonSchem = KeyValueSchema <string, string> .Of(ISchema <string> .String, ISchema <string> .String); var builder = new ConsumerConfigBuilder <KeyValue <string, string> >() .Topic(topic) .SubscriptionName($"subscriber-name-{DateTimeHelper.CurrentUnixTimeMillis()}") .AckTimeout(TimeSpan.FromMilliseconds(20000)) .ForceTopicCreation(true) .AcknowledgmentGroupTime(0); var consumer = _client.NewConsumer(jsonSchem, builder); var producerConfig = new ProducerConfigBuilder <KeyValue <string, string> >() .ProducerName(topic.Split("/").Last()) .Topic(topic) .Schema(jsonSchem) .SendTimeout(10000); var producer = _client.NewProducer(jsonSchem, producerConfig); for (var i = 0; i < 10; i++) { var metadata = new Dictionary <string, string> { ["Key"] = "Single", ["Properties"] = JsonSerializer.Serialize(new Dictionary <string, string> { { "Tick", DateTime.Now.Ticks.ToString() } }, new JsonSerializerOptions { WriteIndented = true }) }; var id = producer.NewMessage().Properties(metadata).Value <string, string>(new KeyValue <string, string>("Ebere", $"[{i}]Ebere")).Send(); _output.WriteLine(id.ToString()); } Thread.Sleep(TimeSpan.FromSeconds(5)); for (var i = 0; i < 10; i++) { var msg = consumer.Receive(); if (msg != null) { var kv = msg.Value; _output.WriteLine($"key:{kv.Key}, value:{kv.Value}"); } } }
public static ISchema <KeyValue <K, V> > NewKeyValueSchema <K, V>(Type key, Type value, SchemaType type) { return(KeyValueSchema <K, V> .Of(key, value, type)); }
public static ISchema <KeyValue <K, V> > NewKeyValueSchema <K, V>(ISchema <K> keySchema, ISchema <V> valueSchema, KeyValueEncodingType keyValueEncodingType) { return(KeyValueSchema <K, V> .Of(keySchema, valueSchema, keyValueEncodingType)); }
public static ISchema <KeyValue <K, V> > NewKeyValueSchema <K, V>(ISchema <K> keySchema, ISchema <V> valueSchema) { //return catchExceptions(() => (Schema<KeyValue<K, V>>)getStaticMethod("org.apache.pulsar.client.impl.schema.KeyValueSchema", "of", typeof(Schema), typeof(Schema)).invoke(null, KeySchema, ValueSchema)); return(KeyValueSchema <K, V> .Of(keySchema, valueSchema)); }