public async Task Run( [ServiceBusTrigger("neworders", Connection = "ServiceBus")] NewOrderMessage message, [CosmosDB("ordersservice", "data", ConnectionStringSetting = "CosmosDB")] IAsyncCollector <NewOrderMessage> data, [ServiceBus("ordersforshipping", Connection = "ServiceBus")] IAsyncCollector <NewOrderMessage> messages, [SignalR(HubName = "ordersHub", ConnectionStringSetting = "SignalR")] IAsyncCollector <SignalRMessage> notificationMessages, ILogger log) { log.LogInformation("CreateNewOrder SB queue trigger function processed a request."); // TODO: talk to other systems, do checks etc. ... - the REAL work :-) try { await data.AddAsync(message); await data.FlushAsync(); } catch (DocumentClientException dcx) { // TODO: retry policy... log.LogError(dcx, "Cosmos DB Error"); throw; } try { await messages.AddAsync(message); await messages.FlushAsync(); } catch (ServiceBusException sbx) { // TODO: retry policy... log.LogError(sbx, "Service Bus Error"); throw; } // NOTE: Group feature not yet available in SignalR binding var messageToNotify = new { userId = message.UserId, orderId = message.Order.Id }; await notificationMessages.AddAsync(new SignalRMessage { Target = "orderCreated", Arguments = new[] { messageToNotify } }); }
public static async Task Run( [ServiceBusTrigger("ordersforshipping", Connection = "ServiceBus")] NewOrderMessage message, [ServiceBus("shippingsinitiated", Connection = "ServiceBus")] IAsyncCollector <ShippingCreatedMessage> shippingCreatedMessages, ILogger log) { log.LogInformation($"CreateShipment ServiceBus topic trigger function processed message: {message}"); // NOTE: Look at our complex business logic! // TODO: Yes - do the REAL STUFF here... await Task.Delay(5000); var shippingCreated = new ShippingCreatedMessage { Id = Guid.NewGuid(), Created = DateTime.UtcNow, OrderId = message.Order.Id, UserId = message.UserId }; log.LogInformation("New shipment: {0}", shippingCreated); try { await shippingCreatedMessages.AddAsync(shippingCreated); await shippingCreatedMessages.FlushAsync(); } catch (ServiceBusException sbx) { // TODO: retry policy... log.LogError(sbx, "Service Bus Error"); throw; } }