Skip to content

Instantly share code, notes, and snippets.

View enRose's full-sized avatar
🎯
Focusing

Yini enRose

🎯
Focusing
  • Wellington, New Zealand
View GitHub Profile
[Rule(Category = "Customer", priority = 0)]
public class MustBe18
{
[Run]
public bool IsValid(CustomerRuleContext ctx) =>
ctx.Dob.Date.AddYears(18) <= DateTime.Today.Date;
}
[Rule(Category = "Customer", priority = 1)]
public class MustLiveInCurrentAddressAtLeast1Year
@enRose
enRose / LendingRule.cs
Last active February 1, 2021 01:32
Fictional Lending Rules
public class LendingRule
{
// shared private state all delcared at the top.
// no clear sense as which state is used by which rule,
// apart from giving them a good name or making comments,
// there are no real provision on encapsulation.
public static int Duration = 30;
private int ageOf = 18;
private decimal minimumIncomeOf = 30000;
private int minmumCreditScoreOf = 100;
@enRose
enRose / StepdownRule.cs
Last active January 31, 2021 21:02
Stepdown rule
public class StepdownRule
{
public static int Duration = 30;
public static bool IsInStepdown(DateTime? dateLendingDecisionMade)
{
return dateLendingDecisionMade.HasValue &&
GetRemainingDays(dateLendingDecisionMade.Value) >= 0;
}
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Confluent.Kafka;
using Polly;
using Polly.Contrib.WaitAndRetry;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace RetrykafkaConsumer
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace RetrykafkaConsumer
{
public class Worker : BackgroundService
using System;
using Confluent.Kafka;
using Newtonsoft.Json;
namespace retry
{
public interface IKafkaProducer
{
void Produce<T>(string msgKey, T msgVal, string topic = "retry-transient-error");
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Polly.Contrib.Simmy;
using Polly.Contrib.Simmy.Outcomes;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace retry.Controllers
{
[ApiController]
[Route("[controller]/[action]")]
public class RetryController : ControllerBase
Start Kafka server
kafka-server-start /usr/local/etc/kafka/server.properties
Start Zookeeper
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
Create Kafka Topic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Initialize Producer console