Exemplo n.º 1
0
        private async Task PublishEventToEventGridAsync(Order orderMessage, string operationId, MessageCorrelationInfo correlationInfo)
        {
            var orderCreatedEvent = new OrderCreatedEvent(operationId, orderMessage.Id, orderMessage.Amount, orderMessage.ArticleNumber, correlationInfo);

            await _eventGridPublisher.PublishAsync(orderCreatedEvent);

            Logger.LogInformation("Event {EventId} was published with subject {EventSubject}", orderCreatedEvent.Id, orderCreatedEvent.Subject);
        }
Exemplo n.º 2
0
        public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, Route = "kubernetes/events/forward")] HttpRequest request)
        {
            var payload = await request.ReadAsStringAsync();

            _logger.LogInformation($"Kubernetes event received: {payload}");

            var cloudEvent = _cloudEventFactory.CreateFromRawKubernetesEvent(payload);
            await _eventGridPublisher.PublishAsync(cloudEvent);

            ILoggerExtensions.LogMetric(_logger, "Kubernetes Event Published", 1);
        }
        public async Task PublishSingleEventGridEvent_WithBuilder_ValidParameters_Succeeds()
        {
            // Arrange
            const string eventSubject = "integration-test";
            const string licensePlate = "1-TOM-337";
            var          eventId      = Guid.NewGuid().ToString();
            var          @event       = new NewCarRegistered(eventId, eventSubject, licensePlate);

            IEventGridPublisher publisher = EventPublisherFactory.CreateEventGridEventPublisher(_config);

            // Act
            await publisher.PublishAsync(@event);

            TracePublishedEvent(eventId, @event);

            // Assert
            var receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(eventId);

            ArcusAssert.ReceivedNewCarRegisteredEvent(eventId, @event.EventType, eventSubject, licensePlate, receivedEvent);
        }
Exemplo n.º 4
0
        private async Task PublishEventToEventGridAsync(Order orderMessage, string operationId, MessageCorrelationInfo correlationInfo)
        {
            var eventData = new OrderCreatedEventData(
                orderMessage.Id,
                orderMessage.Amount,
                orderMessage.ArticleNumber,
                correlationInfo);
            var orderCreatedEvent = new CloudEvent(
                CloudEventsSpecVersion.V1_0,
                "OrderCreatedEvent",
                new Uri("http://test-host"),
                operationId,
                DateTime.UtcNow)
            {
                Data            = eventData,
                DataContentType = new ContentType("application/json")
            };

            await _eventGridPublisher.PublishAsync(orderCreatedEvent);

            _logger.LogInformation("Event {EventId} was published with subject {EventSubject}", orderCreatedEvent.Id, orderCreatedEvent.Subject);
        }
        public async Task PublishSingleCloudEvent_WithBuilder_ValidParameters_Succeeds()
        {
            // Arrange
            const string eventSubject = "integration-test";
            const string licensePlate = "1-TOM-337";
            var          eventId      = Guid.NewGuid().ToString();
            var          @event       = new CloudEvent(CloudEventsSpecVersion.V1_0, "NewCarRegistered", new Uri("http://test-host"), eventSubject, eventId)
            {
                Data            = new CarEventData(licensePlate),
                DataContentType = new ContentType("application/json")
            };

            IEventGridPublisher publisher = EventPublisherFactory.CreateCloudEventPublisher(_config);

            // Act
            await publisher.PublishAsync(@event);

            TracePublishedEvent(eventId, @event);

            // Assert
            string receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(eventId);

            ArcusAssert.ReceivedNewCarRegisteredEvent(eventId, @event.Type, eventSubject, licensePlate, receivedEvent);
        }