protected virtual void Dispose(bool disposing) { if (disposing) { _eventGridClient?.Dispose(); } }
public Task Disconnect() { _isConnected = false; _endpoint = null; _key = null; _topic = null; _subject = null; _eventType = null; _dataVersion = null; _eventGridClient.Dispose(); _eventGridClient = null; _consoleLoggerService.Log(value: _translationsService.GetString("EventGridDisconnected"), logType: ConsoleLogTypes.EventGrid); return(Task.FromResult(true)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Pump2EG function processed a request."); string responseMessage; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); string sSpawnFactor = data?.spawnFactor; int spawnFactor = (string.IsNullOrEmpty(sSpawnFactor)) ? 0 : int.Parse(sSpawnFactor); string topicEndpoint = Environment.GetEnvironmentVariable("EG_EP"); string topicKey = Environment.GetEnvironmentVariable("EG_KEY"); string topicHostname = new Uri(topicEndpoint).Host; TopicCredentials topicCredentials = new TopicCredentials(topicKey); EventGridClient egClient = new EventGridClient(topicCredentials); for (int i = 0; i < spawnFactor; i++) { List <EventGridEvent> eventsList = new List <EventGridEvent>(); EventGridEvent mess = GetEvent($"wow-{i}"); eventsList.Add(mess); try{ await egClient.PublishEventsAsync(topicHostname, eventsList); }catch (Exception ex) { log.LogInformation($"Pump2EG Exception found {ex.Message}"); } } log.LogInformation($"Pump2EG sent: {spawnFactor} messages to a grid"); responseMessage = $"sent {spawnFactor} messages to the grid"; egClient.Dispose(); return(new OkObjectResult(responseMessage)); }
public void Dispose() { _eventGridClient.Dispose(); }