/// <summary> /// Convenience method for adding an item easily from a JSON representation of data to add to the Outbox. Using /// this approach is highly flexible as the payload can control the Outbox and publishing process in an non-coupled /// way (via late binding). Validation of required fields will result in exceptions. /// This will parse and process the json payload with the Transactional Outbox using Default implementations (e.g. GUID identifier). /// This method assumes the current Transaction and associated Connection is valid and will use it but will not commit the Transaction! /// </summary> /// <param name="sqlTransaction"></param> /// <param name="jsonText"></param> /// <param name="publishTopic"></param> /// <param name="fifoGroupingIdentifier"></param> /// <returns></returns> public static async Task <ISqlTransactionalOutboxItem <Guid> > AddTransactionalOutboxPendingItemAsync( this SqlTransaction sqlTransaction, string jsonText, string publishTopic = null, string fifoGroupingIdentifier = null ) { var payloadBuilder = PayloadBuilder.FromJsonSafely(jsonText); //Publishing Target may be defined in the Payload OR as a discrete parameter that overrides the payload, // but it is REQUIRED! var publishingTarget = publishTopic ?? payloadBuilder.PublishTarget; publishingTarget.AssertNotNullOrWhiteSpace(nameof(payloadBuilder.PublishTarget), "No Publishing Topic was defined in the Payload or as a parameter."); //FIFO Grouping Identifier may be defined in the Payload OR as a discrete parameter that overrides the payload, // but it is OPTIONAL. var fifoGroupId = fifoGroupingIdentifier ?? payloadBuilder.FifoGroupingId; var results = await sqlTransaction .AddTransactionalOutboxPendingItemAsync( publishingTarget, payloadBuilder.ToJObject(), fifoGroupId ) .ConfigureAwait(false); return(results); }