public void Purge()
 {
     lock (_lock)
     {
         _queueClient.ClearMessages();
     }
 }
Exemple #2
0
        public async Task Run(
            [TimerTrigger(
                 "%Gatsby:QueueSchedule%",
                 UseMonitor = false
                 )] TimerInfo timer
            )
        {
            try
            {
                var message = queueClient.PeekMessage();

                var bodyString = message.Value?.Body.ToString();

                if (!string.IsNullOrWhiteSpace(bodyString))
                {
                    var queueItem = JsonConvert.DeserializeObject <QueueItem>(bodyString);

                    queueClient.ClearMessages();

                    await gatsbyProxy.ForwardWebhook(queueItem.Webhook, queueItem.GatsbyWebhook);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }
Exemple #3
0
        public async void Can_Publish_Event_To_EventGrid()
        {
            //arrange
            _httpClient = new HttpClient();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            _httpClient.DefaultRequestHeaders.Add("aeg-sas-key", TopicSettings.Key);

            _pause = new ManualResetEvent(false);

            _queueClient = new QueueClient(ProxySettings.StorageAccountConnectionString, ProxySettings.QueueName);

            _queueClient.CreateIfNotExists();
            _queueClient.ClearMessages();

            var myEvent = new MyEvent()
            {
                Type          = "TestEvent",
                Version       = "V1.0",
                CorrelationId = Guid.NewGuid().ToString()
            };

            //act
            var result = await PublishEventAsync(myEvent);

            //assert
            Assert.True(result.IsSuccessStatusCode);

            PollStorageQueueUntilEventArrives();

            QueueMessage[] messages         = _queueClient.ReceiveMessages();
            var            firstMessageJson = Encoding.UTF8.GetString(Convert.FromBase64String(messages.First().MessageText));
            var            cloudEvent       = JsonConvert.DeserializeObject <CloudEvent <MyEvent> >(firstMessageJson);

            Assert.Equal(cloudEvent.Data.Type, myEvent.Type);
            Assert.Equal(cloudEvent.Data.Version, myEvent.Version);
            Assert.Equal(cloudEvent.Data.CorrelationId, myEvent.CorrelationId);
        }