You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the _:::no-loc text="Program.cs":::_ file of your client-consuming project, call the <xref:Microsoft.Extensions.Hosting.AspireKafkaProducerExtensions.AddKafkaProducer%2A> extension method to register an `IProducer<TKey, TValue>` for use via the dependency injection container. The method takes two generic parameters corresponding to the type of the key and the type of the message to send to the broker. These generic parameters are used by `AddKafkaProducer` to create an instance of `ProducerBuilder<TKey, TValue>`. This method also takes connection name parameter.
> The `connectionName` parameter must match the name used when adding the Kafka resource in the AppHost project. In other words, when you call `AddKafka` and provide a name of `kafka` that same name should be used when calling `AddKafkaProducer`. For more information, see [Add Kafka server resource](#add-kafka-server-resource).
169
+
167
170
You can then retrieve the `IProducer<TKey, TValue>` instance using dependency injection. For example, to retrieve the producer from an `IHostedService`:
168
171
169
172
```csharp
@@ -180,9 +183,12 @@ For more information on workers, see [Worker services in .NET](/dotnet/core/exte
180
183
To register an `IConsumer<TKey, TValue>` for use via the dependency injection container, call the <xref:Microsoft.Extensions.Hosting.AspireKafkaConsumerExtensions.AddKafkaConsumer%2A> extension method in the _:::no-loc text="Program.cs":::_ file of your client-consuming project. The method takes two generic parameters corresponding to the type of the key and the type of the message to receive from the broker. These generic parameters are used by `AddKafkaConsumer` to create an instance of `ConsumerBuilder<TKey, TValue>`. This method also takes connection name parameter.
> The `connectionName` parameter must match the name used when adding the Kafka resource in the AppHost project. In other words, when you call `AddKafka` and provide a name of `kafka` that same name should be used when calling `AddKafkaComsumer`. For more information, see [Add Kafka server resource](#add-kafka-server-resource).
191
+
186
192
You can then retrieve the `IConsumer<TKey, TValue>` instance using dependency injection. For example, to retrieve the consumer from an `IHostedService`:
187
193
188
194
```csharp
@@ -210,15 +216,15 @@ The .NET Aspire Apache Kafka integration provides multiple options to configure
210
216
When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddKafkaProducer()` or `builder.AddKafkaProducer()`:
0 commit comments