public async Task Invoke(HttpContext context, IDictionary <string, string> parameters) { if (context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { // CORS - this is super basic... var headers = context.Response.Headers; headers["Access-Control-Allow-Origin"] = "*"; headers["Access-Control-Allow-Methods"] = "POST"; headers["Access-Control-Allow-Headers"] = context.Request.Headers["Access-Control-Request-Headers"]; context.Response.StatusCode = 200; await context.Response.WriteAsync(""); return; } IEnumerable <Message> messages = null; if (context.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase)) { try { messages = ReadMessage(context.Request).ToArray(); foreach (var message in messages) { _messageServerBus.SendMessage(message); } } catch (JsonReaderException exception) { await context.RespondWith(new InvalidJsonProblem(exception).EnableCors()); return; } catch (Exception exception) { await context.RespondWith(new ExceptionProblem(exception).EnableCors()); return; } await context.RespondWith( new HttpStatusResponse(HttpStatusCode.Accepted, "Accepted: " + string.Join(", ", messages.Select(m => m.Id.ToString("N")))) .EnableCors()); } else { await context.RespondWith( new InvalidMethodProblem(context.Request.Method, "POST") .EnableCors()); } }
public async Task Handle(IHttpContext context) { var envelope = ReadMessage(context.Request); _messageServerBus.SendMessage(envelope); // TEST CODE ONLY!!!! var response = context.Response; response.SetHeader("Content-Type", "text/plain"); var data = Encoding.UTF8.GetBytes(envelope.Payload); await response.WriteAsync(data); // TEST CODE ONLY!!!! }
public async Task PublishMessage(IMessage message) { var newMessage = _messageConverter.ConvertMessage(message); await _messageBus.SendMessage(newMessage); }
public void PublishMessage(IMessage message) { _messageBus.SendMessage(message); }
public async Task HandleMessage(MessageEnvelope envelope) { await _serverBroker.SendMessage(envelope); }