예제 #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _eventGridClient?.Dispose();
     }
 }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
 public void Dispose()
 {
     _eventGridClient.Dispose();
 }