Distributed Lock implementation using Zookeeper in .NET Core

public class MyService{private readonly IDistributedLockerFactory distributedLockerFactory;private string data = "";public MyService(IDistributedLockerFactory distributedLockerFactory){  this.distributedLockerFactory = distributedLockerFactory;}public async Task<string> LockTest(){   var locker = distributedLockerFactory.Create("foo").GetLocker();   await locker.LockAsync(DoAction);   return data;}
//Callback for acquiring lock
private void DoAction(){//do some action that is needed for distributed processes be //synchronzed Thread.Sleep(2000); data = "lock acquired";}}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store