Giter Site home page Giter Site logo

confluent.restclient's Introduction

Confluent.RestClient

Build status


Confluent.RestClient is a .NET client libaray for Confluent.io REST API

REST API documentation: http://confluent.io/docs/current/kafka-rest/docs/index.html

Implemting your own Confluent client settings.

Confluent client settings can be implemented by extending IConfluentClientSettings, for example

public class MyConfluentClientSettings : IConfluentClientSettings
{
    public string KafkaBaseUrl
    {
        get
        {
            return ConfigurationManager.AppSettings["Confluent.KafkaBaseUrl"];
        }
    }
    
    public TimeSpan RequestTimeout
    {
        get
        {
            return TimeSpan.Parse(ConfigurationManager.AppSettings["Confluent.RequestTimeout"]);
        }
    }

    public string AuthenticationSchema
    {
        get
        {
            return ConfigurationManager.AppSettings["Confluent.AuthenticationSchema"];
        }
    }

    public string AuthenticationParams
    {
        get
        {
            return ConfigurationManager.AppSettings["Confluent.AuthenticationParams"];
        }
    }
}

You can check out all the client operartions in the Confluent.TestHarness app. They are very easy to use, for example:

Publishing Avro data to TestTopic

// Contract to publish as Avro data 
[DataContract]
public class Person
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public int Age { get; set; }
}


IConfluentClient client = new ConfluentClient(settings);

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);

Creating consumer instance to consume Avro data

IConfluentClient client = new ConfluentClient(settings);
                
var request = new CreateConsumerRequest
{
    // Confluent API will create a new InstanceId if not supplied
    InstanceId = "TestConsumerInstance",
    MessageFormat = MessageFormat.Avro
};

ConfluentResponse<ConsumerInstance> response = await client.CreateConsumerAsync("TestConsumerGroup", request);
ConsumerInstance consumerInstance = response.Payload;

Consume Avro data

IConfluentClient client = new ConfluentClient(settings);

ConfluentResponse<List<AvroMessage<string, Person>>> response
    = await client.ConsumeAsAvroAsync<string, Person>(consumerInstance, "TestTopic");

foreach (AvroMessage<string, Person> message in response.Payload)
{
    Person person = message.Value;
    Console.WriteLine("Name: {0}, Age: {1}", person.Name, person.Age);
}

Commit offset

await client.CommitOffsetAsync(consumerInstance);

confluent.restclient's People

Contributors

bschmidtbauer avatar idonadler avatar josephjeganathan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.