diff --git a/deployments/deploy-consumer-azurefunction.yaml b/deployments/deploy-consumer-azurefunction.yaml index 0101823..f21dc48 100644 --- a/deployments/deploy-consumer-azurefunction.yaml +++ b/deployments/deploy-consumer-azurefunction.yaml @@ -21,7 +21,7 @@ spec: ports: - containerPort: 80 env: - - name: APPSETTING_BrokerList + - name: BrokerList value: kafka.kafka:9092 resources: limits: diff --git a/fruit-consumer-azurefunction/FruitMessage.cs b/fruit-consumer-azurefunction/FruitMessage.cs index 197b279..a08ae80 100644 --- a/fruit-consumer-azurefunction/FruitMessage.cs +++ b/fruit-consumer-azurefunction/FruitMessage.cs @@ -1,15 +1,52 @@ using Avro.Util; +using Confluent.Kafka; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Fruit.Consumer.AzureFunction { - public class FruitMessage + + public class FruitMessage : ISerializer + { + public DateTime? now { get; set; } + public Fruit? fruit { get; set; } + + public FruitMessage(DateTime now, Fruit fruit) + { + this.now = now; + this.fruit = fruit; + } + public FruitMessage() + { + } + public byte[] Serialize(FruitMessage data, SerializationContext context) + { + using (var ms = new MemoryStream()) + { + var settings = new JsonSerializerSettings(); + settings.ContractResolver = new LowercaseContractResolver(); + var json = JsonConvert.SerializeObject(data, Formatting.Indented, settings); + var writer = new StreamWriter(ms); + + writer.Write(json); + writer.Flush(); + ms.Position = 0; + + return ms.ToArray(); + } + } + } + public class LowercaseContractResolver : DefaultContractResolver { - public Date now; - public Fruit fruit; + protected override string ResolvePropertyName(string propertyName) + { + return propertyName.ToLower(); + } } }