-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Microsoft/fbeltrao/output-binding
Initial output support
- Loading branch information
Showing
48 changed files
with
1,313 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Microsoft.Azure.WebJobs.Extensions.Kafka; | ||
|
||
namespace KafkaFunctionSample | ||
{ | ||
public static class ProduceStringTopic | ||
{ | ||
[FunctionName("ProduceStringTopic")] | ||
public static async Task<IActionResult> Run( | ||
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, | ||
[Kafka("stringTopicTenPartitions", BrokerList = "LocalBroker")] IAsyncCollector<KafkaEventData> events, | ||
ILogger log) | ||
{ | ||
try | ||
{ | ||
var kafkaEvent = new KafkaEventData() | ||
{ | ||
Value = await new StreamReader(req.Body).ReadToEndAsync(), | ||
}; | ||
|
||
await events.AddAsync(kafkaEvent); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new Exception("Are you sure the topic 'stringTopicTenPartitions' exists? To created using Confluent Docker quickstart run this command: 'docker-compose exec broker kafka-topics --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 10 --topic stringTopicTenPartitions'", ex); | ||
} | ||
|
||
return new OkResult(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Microsoft.Azure.WebJobs.Extensions.Kafka/Output/IKafkaProducer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Kafka | ||
{ | ||
public interface IKafkaProducer | ||
{ | ||
Task ProduceAsync(string topic, KafkaEventData item, CancellationToken cancellationToken); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Microsoft.Azure.WebJobs.Extensions.Kafka/Output/IKafkaProducerManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Kafka | ||
{ | ||
/// <summary> | ||
/// Manages <see cref="IKafkaProducer"/> | ||
/// </summary> | ||
public interface IKafkaProducerManager | ||
{ | ||
IKafkaProducer Resolve(KafkaAttribute attribute); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Microsoft.Azure.WebJobs.Extensions.Kafka/Output/KafkaAsyncCollector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Kafka | ||
{ | ||
public class KafkaAsyncCollector : IAsyncCollector<KafkaEventData> | ||
{ | ||
private readonly string topic; | ||
private readonly IKafkaProducer producer; | ||
|
||
public KafkaAsyncCollector(string topic, IKafkaProducer producer) | ||
{ | ||
this.topic = topic; | ||
this.producer = producer; | ||
} | ||
|
||
public async Task AddAsync(KafkaEventData item, CancellationToken cancellationToken = default) | ||
{ | ||
await this.producer.ProduceAsync(this.topic, item, cancellationToken); | ||
} | ||
|
||
public Task FlushAsync(CancellationToken cancellationToken = default) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.