public async Task Write(object eventData, HttpContext context)
        {
            var replyEvent = new CloudEvent
            {
                Type            = _eventType,
                Source          = new Uri($"urn:{_eventSource}"),
                Time            = DateTimeOffset.Now,
                DataContentType = "application/json",
                Id   = Guid.NewGuid().ToString(),
                Data = eventData
            };

            _logger.LogInformation("Replying with CloudEvent\n" + replyEvent.GetLog());

            await replyEvent.CopyToHttpResponseAsync(context.Response, ContentMode.Binary, formatter);
        }
Example #2
0
        public async Task Write(string eventData, HttpContext context)
        {
            var replyEvent = new CloudEvent(_eventType, new Uri($"urn:{_eventSource}"))
            {
                DataContentType = new ContentType("application/json"),
                Data            = eventData
            };

            _logger.LogInformation("Replying with CloudEvent\n" + replyEvent.GetLog());

            // Binary format
            //TODO: There must be a better way to convert CloudEvent to HTTP response
            context.Response.Headers.Add("Ce-Id", replyEvent.Id);
            context.Response.Headers.Add("Ce-Specversion", "1.0");
            context.Response.Headers.Add("Ce-Type", replyEvent.Type);
            context.Response.Headers.Add("Ce-Source", replyEvent.Source.ToString());
            context.Response.ContentType = "application/json;charset=utf-8";
            await context.Response.WriteAsync(replyEvent.Data.ToString());
        }