private void OnStarted() { _logger.LogInformation("MoleculerService starting"); _transporter.HeartbeatReceived += _transporter_HeartbeatReceived; _transporter.RequestReceived += _transporter_RequestReceived; _transporter.DiscoverReceived += _transporter_DiscoverReceived; _transporter.InfoReceived += _transporter_InfoReceived; _transporter.Start(_serviceInfo); _logger.LogInformation("MoleculerService started"); _heartbeat = new System.Timers.Timer(HEARTBEAT_PERIOD); _heartbeat.Elapsed += _heartbeat_Elapsed; _heartbeat.Start(); DiscoverMessage discoverMessage = DiscoverMessage.Parse(_serviceInfo); _transporter.Publish("MOL.DISCOVER", discoverMessage); }
public object Call(string actionName, JObject parms, JObject opts) { ServiceEntry entry = _locator.GetServiceEntry(actionName)[0]; if (entry == null) { throw new InvalidOperationException($"service {actionName} not found"); } string newGuid = Guid.NewGuid().ToString(); Semaphores[newGuid] = new Semaphore(0, 1); RequestMessage reqMessage = RequestMessage.Create(actionName, parms, newGuid); string obj = reqMessage.ToString(); _transporter.Publish($"MOL.REQB.{entry.ServiceName}", reqMessage); Semaphores[newGuid].WaitOne(); return(Values[newGuid]); }