/// <summary>
        /// Adds the Activity Consumer Observer to a MassTransit Consumer.
        /// </summary>
        /// <param name="consumeObserverConnector">The <see cref="IConsumeObserverConnector"/> to which the <see cref="IConsumeObserver"/> will be added.</param>
        /// <returns>The<see cref="IConsumeObserverConnector"/>. </returns>
        public static IConsumeObserverConnector AddActivityConsumerObserver([NotNull] this IConsumeObserverConnector consumeObserverConnector)
        {
            if (consumeObserverConnector == null)
            {
                throw new ArgumentNullException(nameof(consumeObserverConnector));
            }

            return(consumeObserverConnector.AddActivityConsumerObserver(null));
        }
        /// <summary>
        /// Adds the Activity Consumer Observer to a MassTransit Consumer.
        /// </summary>
        /// <param name="consumeObserverConnector">The <see cref="IConsumeObserverConnector"/> to which the <see cref="IConsumeObserver"/> will be added.</param>
        /// <param name="tracerFactory">The <see cref="TracerFactory"/> used to get the <see cref="Tracer"/> used for Telemetry.</param>
        /// <returns>The<see cref="IConsumeObserverConnector"/>. </returns>
        private static IConsumeObserverConnector AddActivityConsumerObserver([NotNull] this IConsumeObserverConnector consumeObserverConnector, TracerFactory tracerFactory)
        {
            if (consumeObserverConnector == null)
            {
                throw new ArgumentNullException(nameof(consumeObserverConnector));
            }

            consumeObserverConnector.ConnectConsumeObserver(new MassTransitConsumerActivityObserver(tracerFactory));

            return(consumeObserverConnector);
        }
Ejemplo n.º 3
0
        public static ConnectHandle ConnectAcessoAuditObserver(this IConsumeObserverConnector connector, IServiceProvider provider, Action <IMessageFilterConfigurator> configureFilter = null, IConsumeMetadataFactory metadataFactory = null)
        {
            if (connector == null)
            {
                throw new ArgumentNullException(nameof(connector));
            }

            var specification = new ConsumeMessageFilterSpecification();

            configureFilter?.Invoke(specification);

            var factory = metadataFactory ?? new DefaultConsumeMetadataFactory();
            var mapper  = provider.GetService <IMapper>();

            return(connector.ConnectConsumeObserver(new AcessoAuditEventsObserver(factory, specification.Filter, mapper)));
        }
        /// <summary>
        /// Adds the default Consumer Observer to a MassTransit Consumer.
        /// </summary>
        /// <param name="consumeObserverConnector">The <see cref="IConsumeObserverConnector"/> to which the <see cref="IConsumeObserver"/> will be added.</param>
        /// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
        /// <returns>The <see cref="IConsumeObserverConnector"/>.</returns>
        public static IConsumeObserverConnector AddDefaultConsumerObserver([NotNull] this IConsumeObserverConnector consumeObserverConnector, [NotNull] IServiceProvider serviceProvider)
        {
            if (consumeObserverConnector == null)
            {
                throw new ArgumentNullException(nameof(consumeObserverConnector));
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var contextFactory = serviceProvider.GetRequiredService <IMassTransitContextFactory>();

            consumeObserverConnector.ConnectConsumeObserver(new MassTransitConsumerObserver(contextFactory));

            return(consumeObserverConnector);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add an observer that will audit consumed messages, sending them to the message audit store prior to consumption by the consumer
        /// </summary>
        /// <param name="connector">The bus or endpoint</param>
        /// <param name="store">The audit store</param>
        /// <param name="configureFilter">Filter configuration delegate</param>
        /// <param name="metadataFactory">Message metadata factory. If omitted, the default one will be used.</param>
        public static ConnectHandle ConnectConsumeAuditObserver(this IConsumeObserverConnector connector, IMessageAuditStore store,
                                                                Action <IMessageFilterConfigurator> configureFilter = null, IConsumeMetadataFactory metadataFactory = null)
        {
            if (connector == null)
            {
                throw new ArgumentNullException(nameof(connector));
            }
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }

            var specification = new ConsumeMessageFilterSpecification();

            configureFilter?.Invoke(specification);

            var factory = metadataFactory ?? new DefaultConsumeMetadataFactory();

            return(connector.ConnectConsumeObserver(new AuditConsumeObserver(store, factory, specification.Filter)));
        }
        /// <summary>
        /// Adds the Activity Consumer Observer with Tracing to a MassTransit Consumer.
        /// </summary>
        /// <param name="consumeObserverConnector">The <see cref="IConsumeObserverConnector"/> to which the <see cref="IConsumeObserver"/> will be added.</param>
        /// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
        /// <returns>The<see cref="IConsumeObserverConnector"/>. </returns>
        public static IConsumeObserverConnector AddActivityConsumerObserverWithTracing([NotNull] this IConsumeObserverConnector consumeObserverConnector, [NotNull] IServiceProvider serviceProvider)
        {
            if (consumeObserverConnector == null)
            {
                throw new ArgumentNullException(nameof(consumeObserverConnector));
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var tracerFactory = serviceProvider.GetService <TracerFactory>();

            return(consumeObserverConnector.AddActivityConsumerObserver(tracerFactory));
        }
        /// <summary>
        /// Registers an <see cref="IConsumeObserver"/> which resolves the actual observer from the container lifetime scope
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="lifetimeScope">The default lifetime scope</param>
        /// <returns></returns>
        public static ConnectHandle ConnectAutofacConsumeObserver(this IConsumeObserverConnector connector, ILifetimeScope lifetimeScope)
        {
            var observer = new AutofacConsumeObserver(lifetimeScope);

            return(connector.ConnectConsumeObserver(observer));
        }
        /// <summary>
        /// Registers an <see cref="IConsumeObserver"/> which resolves the actual observer from the container lifetime scope
        /// </summary>
        /// <param name="connector"></param>
        /// <returns></returns>
        public static ConnectHandle ConnectAutofacConsumeObserver(this IConsumeObserverConnector connector)
        {
            var observer = new AutofacConsumeObserver();

            return(connector.ConnectConsumeObserver(observer));
        }