Skip to content

Instantly share code, notes, and snippets.

View aramkoukia's full-sized avatar
🏠
Working from home

Aram Koukia aramkoukia

🏠
Working from home
View GitHub Profile
@aramkoukia
aramkoukia / OptOutController.cs
Created April 14, 2018 20:10
Opt Out of Versioning
[ApiVersionNeutral]
[Route("api/optout")]
public class OptOutControler : Controller
{
[HttpGet]
public string Get() => HttpContext.GetRequestedApiVersion().ToString();
}
@aramkoukia
aramkoukia / Controller.cs
Created April 14, 2018 19:55
Specifying different versions
namespace Product.CommandService.Controllers.Product.V1
{
[ApiVersion("1.0")]
[Produces("application/json")]
[Route("api/Product")]
public class ProductController : Controller
{
}
}
@aramkoukia
aramkoukia / Startup.cs
Created April 14, 2018 19:45
Adding API Version to .Net Core APIs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddApiVersioning(o => o.ApiVersionReader = new HeaderApiVersionReader("api-version"));
}
using Confluent.Kafka;
using Confluent.Kafka.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
namespace kafka_consumer
{
class Program
{
using Confluent.Kafka;
using Confluent.Kafka.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
namespace kafka_prototype
{
class Program
{
Policy
.Timeout(30, onTimeout: (context, timespan, task) =>
{
YourFunctionWhenTimeout();
});
Policy
.Handle<Exception>()
.Fallback<UserAvatar>(() => UserAvatar.GetRandomAvatar())
Action<Exception, TimeSpan> onBreak = (exception, timespan) => { ... };
Action onReset = () => { ... };
CircuitBreakerPolicy breaker = Policy
.Handle<Exception>()
.CircuitBreaker(2, TimeSpan.FromMinutes(1), onBreak, onReset);
Policy
.Handle<Exception>()
.CircuitBreaker(2, TimeSpan.FromMinutes(1));
Policy
.Handle<Exception>()
.WaitAndRetry(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
}, (exception, timeSpan, context) => {
YourFunction();
});