public async Task CreateNotification() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <CommunicationTest> >(); var user = await GetRandomUserAsync(); logger.LogInformation($"User = {user}"); var participantReference = CreateParticipantReference.FromTimestamp(GetUniqueNow()); logger.LogInformation($"Participant reference = {participantReference}"); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference); logger.LogInformation($"Participant ID = {participantId}"); var topicReference = CreateTopicReference.FromUserId(user.Id); logger.LogInformation($"Topic reference = {topicReference}"); var topicFields = new Dictionary <string, string>() { { "Key1", "Value1" }, { "Key2", "Value2" } }; var topicId = await CommunicationMicroService.AllocateTopicAsync(topicReference, topicFields).ConfigureAwait(false); logger.LogInformation($"Topic ID = {topicId}"); await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId); }
public async Task HandleShipmentEventAsync(MFulfillment_ShipmentEvent eventData) { using var log = BeginFunction(nameof(FulfillmentEventMicroService), nameof(HandleShipmentEventAsync), eventData); try { using var ctx = CreateQuiltContext(); switch (eventData.EventType) { case MFulfillment_ShipmentEventTypes.Process: { var fulfillableIds = new HashSet <long>(); foreach (var shipmentRequestId in eventData.ShipmentRequestIds) { var mShipmentRequest = await FullfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId).ConfigureAwait(false); foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems) { var mFulfillable = await FullfillmentMicroService.GetFulfillableByItemAsync(mShipmentRequestItem.FulfillableItemId).ConfigureAwait(false); var fulfillableId = mFulfillable.FulfillableId; if (fulfillableIds.Contains(fulfillableId)) { _ = fulfillableIds.Add(fulfillableId); if (TryParseOrderId.FromFulfillableReference(mFulfillable.FulfillableReference, out var orderId)) { var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false); var userId = ParseUserId.FromOrdererReference(mOrder.OrdererReference); var participantReference = CreateParticipantReference.FromUserId(userId); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference).ConfigureAwait(false); var topicReference = CreateTopicReference.FromOrderId(orderId); var topicId = await CommunicationMicroService.AllocateTopicAsync(topicReference, null).ConfigureAwait(false); await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId).ConfigureAwait(false); } } } } } break; } await Task.CompletedTask.ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }