public static bool HasValue(this ExtendableOptions options) { var messageId = options.GetMessageId(); if (messageId is not null) { return(true); } if (options is SendOptions sendOptions) { if (sendOptions.GetDeliveryDate().HasValue || sendOptions.GetDeliveryDelay().HasValue) { return(true); } } var headers = options.GetHeaders(); if (headers.Any()) { return(true); } var extensions = options.GetExtensions(); if (extensions is not null) { return(ContextBagHelper.HasContent(extensions)); } return(false); }
/// <summary> /// Returns whether immediate dispatch has been requested by <see cref="RequireImmediateDispatch" /> or not. /// </summary> /// <param name="options">The options being extended.</param> /// <returns><c>True</c> if immediate dispatch was requested, <c>False</c> otherwise.</returns> public static bool RequiredImmediateDispatch(this ExtendableOptions options) { Guard.AgainstNull(nameof(options), options); options.GetExtensions().TryGet(out RoutingToDispatchConnector.State state); return(state?.ImmediateDispatch ?? false); }
/// <summary> /// Requests that the message be dispatched to the transport immediately. /// This means that the message is ACKed by the transport as soon as the call to send returns. /// The message will not be enlisted in any current receive transaction even if the transport support it. /// </summary> /// <param name="options">The options being extended.</param> public static void RequireImmediateDispatch(this ExtendableOptions options) { Guard.AgainstNull(nameof(options), options); options.GetExtensions().Set(new RoutingToDispatchConnector.State { ImmediateDispatch = true }); }
/// <summary> /// Allows customization of the outgoing native message sent using <see cref="IMessageSession"/>. /// </summary> /// <param name="options">Option being extended.</param> /// <param name="customization">Customization action.</param> public static void CustomizeNativeMessage(this ExtendableOptions options, Action <ServiceBusMessage> customization) { var extensions = options.GetExtensions(); if (extensions.TryGet <Action <ServiceBusMessage> >(NativeMessageCustomizationBehavior.CustomizationKey, out _)) { throw new InvalidOperationException("Native outgoing message has already been customized. Do not apply native outgoing message customization more than once per message."); } extensions.Set(NativeMessageCustomizationBehavior.CustomizationKey, customization); }
static IOutgoingAttachments GetAttachments(this ExtendableOptions options) { var contextBag = options.GetExtensions(); if (contextBag.TryGet <IOutgoingAttachments>(out var attachments)) { return(attachments); } attachments = new OutgoingAttachments(); contextBag.Set(attachments); return(attachments); }
static IOutgoingAttachments GetAttachments(this ExtendableOptions options) { Guard.AgainstNull(options, nameof(options)); var contextBag = options.GetExtensions(); // check the context for a IOutgoingAttachments in case a mocked instance is injected for testing if (contextBag.TryGet <IOutgoingAttachments>(out var attachments)) { return(attachments); } attachments = new OutgoingAttachments(); contextBag.Set(attachments); return(attachments); }
async Task CaptureMessages(Func <IMessageSession, Task> operation, ExtendableOptions options) { var pendingOperations = new PendingTransportOperations(); options.GetExtensions().Set(pendingOperations); await operation(rootSession).ConfigureAwait(false); var messageRecords = pendingOperations.Operations.Select(o => o.ToMessageRecord(requestId, TransactionContext.AttemptId)).Cast <SideEffectRecord>().ToList(); var messagesToCheck = pendingOperations.Operations.Select(o => o.ToCheck()).ToArray(); await TransactionContext.AddSideEffects(messageRecords).ConfigureAwait(false); await messageStore.Create(messagesToCheck).ConfigureAwait(false); }
public static void RegisterCancellationToken(this ExtendableOptions options, CancellationToken cancellationToken) { var extensions = options.GetExtensions(); RequestResponseStateLookup.State state; if (extensions.TryGet(out state)) { state.CancellationToken = cancellationToken; } else { state = new RequestResponseStateLookup.State { CancellationToken = cancellationToken }; } extensions.Set(state); }
static RequestResponseStateLookup.State RegisterTokenSource(this ExtendableOptions options, TaskCompletionSourceAdapter adapter) { var extensions = options.GetExtensions(); RequestResponseStateLookup.State state; if (extensions.TryGet(out state)) { state.TaskCompletionSource = adapter; } else { state = new RequestResponseStateLookup.State { TaskCompletionSource = adapter, CancellationToken = CancellationToken.None }; } extensions.Set(state); return(state); }
/// <summary> /// Gets the customization of the outgoing native message sent using <see cref="NServiceBus.SendOptions"/>, <see cref="NServiceBus.PublishOptions"/> or <see cref="NServiceBus.ReplyOptions"/>. /// </summary> /// <param name="options">Option being extended.</param> /// <returns>The customization action or null.</returns> public static Action <ServiceBusMessage> GetNativeMessageCustomization(this ExtendableOptions options) { return(options.GetExtensions().TryGet <Action <ServiceBusMessage> >(NativeMessageCustomizationBehavior.CustomizationKey, out var customization) ? customization : null); }