/// <summary> /// Конвертирует настройки публикации сообщения в заголовки сообщения. /// </summary> /// <param name="options">Настройки публикации сообщения.</param> /// <returns>Заголовки сообщения.</returns> private IDictionary <string, object> ApplyOptions(PublishingOptions options) { var storage = this.Configuration.Options.GetIncomingMessageHeaderStorage().Value; var incomingHeaders = storage.Load() ?? new Dictionary <string, object>(); var outgoingHeaders = new Dictionary <string, object>(incomingHeaders); Headers.ApplyBreadcrumbs(outgoingHeaders, this.endpoint.Address); Headers.ApplyOriginalMessageId(outgoingHeaders); var defaultOptionsMap = new Dictionary <string, Func <Maybe> > { { Headers.Persist, () => this.Configuration.Options.IsPersistently() }, { Headers.Ttl, () => this.Configuration.Options.GetTtl() }, { Headers.Delay, () => this.Configuration.Options.GetDelay() } }; var publishingOptionsDict = options.GetAll(); var keys = defaultOptionsMap.Keys.Union(publishingOptionsDict.Keys).Distinct(); foreach (var key in keys) { var maybeValue = publishingOptionsDict.ContainsKey(key) ? publishingOptionsDict[key] : defaultOptionsMap[key].Invoke(); if (maybeValue.HasValue) { outgoingHeaders[key] = maybeValue.Value; } } return(outgoingHeaders); }
/// <inheritdoc /> public void Handle(IConsumingContext <T> context) { BusProcessingContext.Current = new BusProcessingContext(((IDeliveryContext)context).Delivery, context.Bus); this.@operator .Apply(context.Message) .ForEach( m => { var headers = new Dictionary <string, object>(m.Headers); Headers.ApplyBreadcrumbs(headers, context.Bus.Endpoint.Address); Headers.ApplyOriginalMessageId(headers); context.Bus.Emit(m.Label, m.Payload, headers); }); context.Accept(); }
/// <summary> /// Конвертирует настройки публикации сообщения в заголовки сообщения. /// </summary> /// <param name="options">Настройки публикации сообщения.</param> /// <returns>Заголовки сообщения.</returns> private IDictionary <string, object> ApplyOptions(PublishingOptions options) { var storage = this.Configuration.Options.GetIncomingMessageHeaderStorage().Value; var inputHeaders = storage.Load() ?? new Dictionary <string, object>(); var outputHeaders = new Dictionary <string, object>(inputHeaders); Headers.ApplyBreadcrumbs(outputHeaders, this.endpoint.Address); Headers.ApplyOriginalMessageId(outputHeaders); Maybe <bool> persist = BusOptions.Pick(options.Persistently, this.Configuration.Options.IsPersistently()); Headers.ApplyPersistently(outputHeaders, persist); Maybe <TimeSpan?> ttl = BusOptions.Pick(options.Ttl, this.Configuration.Options.GetTtl()); Headers.ApplyTtl(outputHeaders, ttl); return(outputHeaders); }