Page History
...
Code Block | ||
---|---|---|
| ||
namespace SearchApiTest.Adapter { public class GraphEngineTest { private GraphEngine _graphEngine; [SetUp] public void SetUp() { var logger = TestLogger.Create<GraphEngine>(); var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.Development.json"); var Configuration = builder.Build(); var options = new AppSettings(); Configuration.GetSection("AppSettings") .Bind(options); _graphEngine = new GraphEngine(options, logger); } [TestCase(TestName = "Step0 - 초기화 생성및 연결 Test")] public async Task CreatePersonAreOK() { _graphEngine.RemoveAll().Wait(); var cypher = await _graphEngine.GetCypher(); await cypher.Write .Create(@"(alice:Person {name:'홍길동'})") .ExecuteWithoutResultsAsync(); await cypher.Write .Create(@"(alice:Person {name:'철수'})") .ExecuteWithoutResultsAsync(); await cypher.Write .Create(@"(alice:Movie {name:'스파이더맨'})") .ExecuteWithoutResultsAsync(); await cypher.Write .Create(@"(alice:Movie {name:'타이타닉'})") .ExecuteWithoutResultsAsync(); await cypher.Write .Match(@"(a: Person),(b: Movie)") .Where(@"a.name = '홍길동' AND b.name = '스파이더맨'") .Create(@"(a)-[r:뷰]->(b)").ExecuteWithoutResultsAsync(); await cypher.Write .Match(@"(a: Person),(b: Movie)") .Where(@"a.name = '철수' AND b.name = '타이타닉'") .Create(@"(a)-[r:뷰]->(b)").ExecuteWithoutResultsAsync(); await cypher.Write .Match(@"(a: Person),(b: Person)") .Where(@"a.name = '철수' AND b.name = '홍길동'") .Create(@"(a)-[r:친구]->(b)").ExecuteWithoutResultsAsync(); } } } |
친구가본 영화를 추천하는 간단한 그래프 모델입니다모델이며 브라우져를 통해 연관성이 시각화를 통해 표현됩니다.
이벤트 큐로 확장하기
서비스에서 이벤트가 발생할때마다 Crud를 직접하는것은 서비스의 성능을 느리게할수 있으며, 발생이벤트를 메시징큐에 적재하여
...
Code Block | ||
---|---|---|
| ||
namespace SearchApi.Actors { public class GraphElementIdenty { public string Alice { get; set; } public string Name { get; set; } } public class GraphEvent { public string Action { get; set; } // Create , Relation, Reset public string Alice { get; set; } // AliceName public string Name { get; set; } public GraphElementIdenty From { get; set; } public GraphElementIdenty To { get; set; } } public class GraphEventActor : ReceiveActor { private readonly ILoggingAdapter logger = Context.GetLogger(); private readonly GraphEngine graphEngine; public GraphEventActor(GraphEngine _graphEngine) { logger.Info($"Create GraphEventActor:{Context.Self.Path.Name}"); graphEngine = _graphEngine; ReceiveAsync<GraphEvent>(async graphEvent => { var cypher = await _graphEngine.GetCypher(); switch (graphEvent.Action) { case "Reset": { await _graphEngine.RemoveAll(); } break; case "Create": { await cypher.Write .Create($"(alice:{graphEvent.Alice} {{name:'{graphEvent.Name}'}})") .ExecuteWithoutResultsAsync(); } break; case "Relation": { await cypher.Write .Match($"(a:{graphEvent.From.Alice}),(b:{graphEvent.To.Alice})") .Where($"a.name = '{graphEvent.From.Name}' AND b.name = '{graphEvent.To.Name}'") .Create($"(a)-[r:{graphEvent.Name}]->(b)").ExecuteWithoutResultsAsync(); } break; } }); } } } |
그래프 액터 활용
추천데이터 이벤트를 심플하게 처리하는 액터기입니다발생하는 액터기이며, 로컬작동시에도 서비스를 블락하지 않습니다.
- 대상객체 생성 / 관계를 연결 두가지 기능을 심플하게 수행합니다.
...