Skip to content

Commit

Permalink
add serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
felpasl committed Jul 31, 2023
1 parent 57166b0 commit 79256df
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deployments/deploy-consumer-azurefunction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
ports:
- containerPort: 80
env:
- name: APPSETTING_BrokerList
- name: BrokerList
value: kafka.kafka:9092
resources:
limits:
Expand Down
43 changes: 40 additions & 3 deletions fruit-consumer-azurefunction/FruitMessage.cs
Original file line number Diff line number Diff line change
@@ -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<FruitMessage>
{
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();
}
}
}

0 comments on commit 79256df

Please sign in to comment.