Skip to content

Commit f6d525f

Browse files
authored
Merge pull request #105674 from jsquire/patch-2
In-Proc C# Sample Update
2 parents 8c2d269 + 2da31e4 commit f6d525f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

articles/azure-functions/functions-bindings-event-hubs-output.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,23 @@ The following example shows how to use the `IAsyncCollector` interface to send a
4242
[FunctionName("EH2EH")]
4343
public static async Task Run(
4444
[EventHubTrigger("source", Connection = "EventHubConnectionAppSetting")] EventData[] events,
45-
[EventHub("dest", Connection = "EventHubConnectionAppSetting")]IAsyncCollector<string> outputEvents,
45+
[EventHub("dest", Connection = "EventHubConnectionAppSetting")]IAsyncCollector<EventData> outputEvents,
4646
ILogger log)
4747
{
4848
foreach (EventData eventData in events)
4949
{
50-
// do some processing:
51-
var myProcessedEvent = DoSomething(eventData);
52-
53-
// then send the message
54-
await outputEvents.AddAsync(JsonConvert.SerializeObject(myProcessedEvent));
50+
// Do some processing:
51+
string newEventBody = DoSomething(eventData);
52+
53+
// Queue the message to be sent in the background by adding it to the collector.
54+
// If only the event is passed, an Event Hub partition to be be assigned via
55+
// round-robin for each batch.
56+
await outputEvents.AddAsync(new EventData(newEventBody));
57+
58+
// If your scenario requires that certain events are grouped together in an
59+
// Event Hub partition, you can specify a partition key. Events added with
60+
// the same key will always be assigned to the same partition.
61+
await outputEvents.AddAsync(new EventData(newEventBody), "sample-key");
5562
}
5663
}
5764
```
@@ -311,7 +318,7 @@ In-process C# class library functions supports the following types:
311318

312319
This version of [EventData](/dotnet/api/azure.messaging.eventhubs.eventdata) drops support for the legacy `Body` type in favor of [EventBody](/dotnet/api/azure.messaging.eventhubs.eventdata.eventbody).
313320

314-
Send messages by using a method parameter such as `out string paramName`. To write multiple messages, you can use `ICollector<string>` or `IAsyncCollector<string>` in place of `out string`.
321+
Send messages by using a method parameter such as `out string paramName`. To write multiple messages, you can use `ICollector<EventData>` or `IAsyncCollector<EventData>` in place of `out string`. Partition keys may only be used with `IAsyncCollector<EventData>`.
315322

316323
# [Extension v3.x+](#tab/extensionv3/in-process)
317324

0 commit comments

Comments
 (0)