Exemple #1
0
        /// <summary>
        /// Registers a receiver using the <paramref name="configuration"/>
        /// </summary>
        /// <param name="configuration">
        /// Receiver configuration
        /// </param>
        /// <param name="isCallback">
        /// Denotes if a receiver should handle the callback messages
        /// </param>
        /// <returns>
        /// The <see cref="RabbitReceiver"/>.
        /// </returns>
        public RabbitReceiver RegisterReceiver(IReceiverConfiguration configuration, bool isCallback = false)
        {
            this.logger.Trace(
                $"Registering a new receiver of [{configuration.Label}] with connection string [{configuration.Options.GetConnectionString()}]");

            RabbitReceiver receiver;

            if (isCallback)
            {
                receiver = new RabbitCallbackReceiver(this, configuration, this.connectionPool);

                // No need to subscribe to listener-created event as it will not be fired by the callback receiver. A callback listener is not checked with listeners in other receivers for compatibility.
            }
            else
            {
                receiver = new RabbitReceiver(this, configuration, this.connectionPool);
                receiver.ListenerCreated += this.OnListenerCreated;
            }

            this.ComponentTracker.Register(receiver);

            this.logger.Trace(
                $"A receiver of [{configuration.Label}] with connection string [{configuration.Options.GetConnectionString()}] registered successfully");
            return(receiver);
        }
Exemple #2
0
        /// <summary>
        /// The resolve for.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// The <see cref="Listener"/>.
        /// </returns>
        public Listener ResolveFor(IReceiverConfiguration configuration)
        {
            using (RabbitChannel channel = this.bus.OpenChannel())
            {
                var topologyBuilder = new TopologyBuilder(channel);
                var builder         = new SubscriptionEndpointBuilder(this.bus.Endpoint, topologyBuilder, configuration);

                Maybe <Func <ISubscriptionEndpointBuilder, ISubscriptionEndpoint> > endpointBuilder = configuration.Options.GetEndpointBuilder();

                Assumes.True(endpointBuilder != null, "EndpointBuilder is null for [{0}].", configuration.Label);

                ISubscriptionEndpoint endpoint = endpointBuilder.Value(builder);

                lock (this.listeners)
                {
                    Listener listener = this.listeners.FirstOrDefault(l => l.Endpoint.ListeningSource.Equals(endpoint.ListeningSource));
                    if (listener == null)
                    {
                        listener = new Listener(this.bus, endpoint, (RabbitReceiverOptions)configuration.Options, this.bus.Configuration.ValidatorRegistry);
                        this.listeners.Add(listener);
                    }
                    else
                    {
                        EnsureConfigurationIsCompatible(listener, configuration);
                    }

                    return(listener);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RabbitReceiver"/> class.
 /// </summary>
 /// <param name="bus">A reference to the bus containing the receiver</param>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="connectionPool">
 /// A bus connection pool
 /// </param>
 public RabbitReceiver(RabbitBus bus, IReceiverConfiguration configuration, IConnectionPool <IRabbitConnection> connectionPool)
     : base(configuration)
 {
     this.bus             = bus;
     this.connectionPool  = connectionPool;
     this.receiverOptions = (RabbitReceiverOptions)configuration.Options;
     this.logger          = LogManager.GetLogger($"{this.GetType().FullName}(Endpoint=\"{this.bus.Endpoint}\")");
 }
Exemple #4
0
        /// <summary>
        /// Registers a receiver using the <paramref name="configuration"/>
        /// </summary>
        /// <param name="configuration">
        /// Receiver configuration
        /// </param>
        /// <returns>
        /// The <see cref="RabbitReceiver"/>.
        /// </returns>
        public RabbitReceiver RegisterReceiver(IReceiverConfiguration configuration)
        {
            this.logger.Trace(
                $"Registering a new receiver of [{configuration.Label}] with connection string [{configuration.Options.GetConnectionString()}]");

            var receiver = new RabbitReceiver(this, configuration, this.connectionPool);

            receiver.ListenerRegistered += this.OnListenerRegistered;
            this.ComponentTracker.Register(receiver);

            this.logger.Trace(
                $"A receiver of [{configuration.Label}] with connection string [{configuration.Options.GetConnectionString()}] registered successfully");
            return(receiver);
        }
Exemple #5
0
        /// <summary>
        /// The ensure configuration is compatible.
        /// </summary>
        /// <param name="listener">
        /// The listener.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <exception cref="BusConfigurationException">
        /// </exception>
        private static void EnsureConfigurationIsCompatible(Listener listener, IReceiverConfiguration configuration)
        {
            RabbitReceiverOptions existing = listener.ReceiverOptions;
            var other = (RabbitReceiverOptions)configuration.Options;

            Action <Func <RabbitReceiverOptions, object>, string> compareAndThrow = (getOption, optionName) =>
            {
                if (getOption(existing) != getOption(other))
                {
                    throw new BusConfigurationException("Listener on [{0}] is not compatible with subscription of [{1}] due to option mismatch [{2}].".FormatEx(listener.Endpoint.ListeningSource, configuration.Label, optionName));
                }
            };

            compareAndThrow(o => o.IsAcceptRequired(), "AcceptIsRequired");
            compareAndThrow(o => o.GetParallelismLevel(), "ParallelismLevel");
            compareAndThrow(o => o.GetFailedDeliveryStrategy(), "FailedDeliveryStrategy");
            compareAndThrow(o => o.GetQoS(), "QoS");
        }
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="SubscriptionEndpointBuilder"/>.
 /// </summary>
 /// <param name="endpoint">Конечная точка шины сообщений.</param>
 /// <param name="topology">Построитель топологии шины сообщений.</param>
 /// <param name="receiver">Конфигурация получателя ответных сообщений.</param>
 public SubscriptionEndpointBuilder(IEndpoint endpoint, ITopologyBuilder topology, IReceiverConfiguration receiver)
 {
     this.Endpoint = endpoint;
     this.Topology = topology;
     this.Receiver = receiver;
 }
Exemple #7
0
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="AbstractReceiver"/>.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 protected AbstractReceiver(IReceiverConfiguration configuration)
 {
     this.Configuration = configuration;
 }
Exemple #8
0
 public RabbitCallbackReceiver(RabbitBus bus, IReceiverConfiguration configuration, IConnectionPool <IRabbitConnection> connectionPool)
     : base(bus, configuration, connectionPool)
 {
 }
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="RabbitReceiver"/>.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="listenerRegistry">
 /// The listener registry.
 /// </param>
 public RabbitReceiver(IReceiverConfiguration configuration, ListenerRegistry listenerRegistry)
     : base(configuration)
 {
     this.listenerRegistry = listenerRegistry;
 }
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="SubscriptionEndpointBuilder"/>.
 /// </summary>
 /// <param name="endpoint">Конечная точка шины сообщений.</param>
 /// <param name="topology">Построитель топологии шины сообщений.</param>
 /// <param name="receiver">Конфигурация получателя ответных сообщений.</param>
 public SubscriptionEndpointBuilder(IEndpoint endpoint, ITopologyBuilder topology, IReceiverConfiguration receiver)
 {
     this.Endpoint = endpoint;
     this.Topology = topology;
     this.Receiver = receiver;
 }
        /// <summary>
        /// The resolve for.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// The <see cref="Listener"/>.
        /// </returns>
        public Listener ResolveFor(IReceiverConfiguration configuration)
        {
            using (RabbitChannel channel = this.bus.OpenChannel())
            {
                var topologyBuilder = new TopologyBuilder(channel);
                var builder = new SubscriptionEndpointBuilder(this.bus.Endpoint, topologyBuilder, configuration);

                Maybe<Func<ISubscriptionEndpointBuilder, ISubscriptionEndpoint>> endpointBuilder = configuration.Options.GetEndpointBuilder();

                Assumes.True(endpointBuilder != null, "EndpointBuilder is null for [{0}].", configuration.Label);

                ISubscriptionEndpoint endpoint = endpointBuilder.Value(builder);

                lock (this.listeners)
                {
                    Listener listener = this.listeners.FirstOrDefault(l => l.Endpoint.ListeningSource.Equals(endpoint.ListeningSource));
                    if (listener == null)
                    {
                        listener = new Listener(this.bus, endpoint, (RabbitReceiverOptions)configuration.Options, this.bus.Configuration.ValidatorRegistry);
                        this.listeners.Add(listener);
                    }
                    else
                    {
                        EnsureConfigurationIsCompatible(listener, configuration);
                    }

                    return listener;
                }
            }
        }
        /// <summary>
        /// The ensure configuration is compatible.
        /// </summary>
        /// <param name="listener">
        /// The listener.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <exception cref="BusConfigurationException">
        /// </exception>
        private static void EnsureConfigurationIsCompatible(Listener listener, IReceiverConfiguration configuration)
        {
            RabbitReceiverOptions existing = listener.ReceiverOptions;
            var other = (RabbitReceiverOptions)configuration.Options;

            Action<Func<RabbitReceiverOptions, object>, string> compareAndThrow = (getOption, optionName) =>
                {
                    if (getOption(existing) != getOption(other))
                    {
                        throw new BusConfigurationException("Listener on [{0}] is not compatible with subscription of [{1}] due to option mismatch [{2}].".FormatEx(listener.Endpoint.ListeningSource, configuration.Label, optionName));
                    }
                };

            compareAndThrow(o => o.IsAcceptRequired(), "AcceptIsRequired");
            compareAndThrow(o => o.GetParallelismLevel(), "ParallelismLevel");
            compareAndThrow(o => o.GetFailedDeliveryStrategy(), "FailedDeliveryStrategy");
            compareAndThrow(o => o.GetQoS(), "QoS");
        }