> ## Documentation Index
> Fetch the complete documentation index at: https://docs.streamnative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Build Producer

Let's create the .NET producer application by pasting the following code into a file `producer/producer.cs`.

```csharp theme={null}
using Confluent.Kafka;
using System;

class Producer {
    static void Main(string[] args)
    {
        const string topic = "purchases";

        string[] users = { "eabara", "jsmith", "sgarcia", "jbernard", "htanaka", "awalther" };
        string[] items = { "book", "alarm clock", "t-shirts", "gift card", "batteries" };

        var config = new ProducerConfig
        {
            // User-specific properties that you must set
            BootstrapServers = "<BOOTSTRAP SERVERS>",
            SaslUsername     = "unused",
            SaslPassword     = "token:<API KEY>",

            // Fixed properties
            SecurityProtocol = SecurityProtocol.SaslSsl,
            SaslMechanism    = SaslMechanism.Plain,
            Acks             = Acks.All
        };

        using (var producer = new ProducerBuilder<string, string>(config).Build())
        {
            var numProduced = 0;
            Random rnd = new Random();
            const int numMessages = 10;
            for (int i = 0; i < numMessages; ++i)
            {
                var user = users[rnd.Next(users.Length)];
                var item = items[rnd.Next(items.Length)];

                producer.Produce(topic, new Message<string, string> { Key = user, Value = item },
                    (deliveryReport) =>
                    {
                        if (deliveryReport.Error.Code != ErrorCode.NoError) {
                            Console.WriteLine($"Failed to deliver message: {deliveryReport.Error.Reason}");
                        }
                        else {
                            Console.WriteLine($"Produced event to topic {topic}: key = {user,-10} value = {item}");
                            numProduced += 1;
                        }
                    });
            }

            producer.Flush(TimeSpan.FromSeconds(10));
            Console.WriteLine($"{numProduced} messages were produced to topic {topic}");
        }
    }
}
```

Fill in the appropriate `<BOOTSTRAP SERVERS>` endpoint and `<API KEY>` in the `BootstrapServers` and `SaslPassword` properties where the client configuration `config` object is created.

You can test the syntax before proceding by running the following command:

```bash theme={null}
cd producer
dotnet build producer.csproj
```
