/// <summary>
        /// Registers a management endpoint on the bus, which can be used to control
        /// filters and other management control points on the bus.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="host">The host where the endpoint is to be created</param>
        /// <param name="configure">Configure additional values of the underlying receive endpoint</param>
        /// <returns></returns>
        public static IManagementEndpointConfigurator ManagementEndpoint(this IRabbitMqBusFactoryConfigurator configurator,
                                                                         IRabbitMqHost host, Action <IRabbitMqReceiveEndpointConfigurator> configure = null)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            var queueName = host.GetTemporaryQueueName("manage-");

            var endpointConfigurator = new RabbitMqReceiveEndpointSpecification(host, queueName)
            {
                AutoDelete = true,
                Durable    = false
            };

            configure?.Invoke(endpointConfigurator);

            configurator.AddReceiveEndpointSpecification(endpointConfigurator);

            var managementEndpointConfigurator = new ManagementEndpointConfigurator(endpointConfigurator);

            return(managementEndpointConfigurator);
        }
        /// <summary>
        /// Creates a Turnout endpoint on the bus, which is capable of executing long-running jobs without hanging the consumer pipeline.
        /// Multiple receive endpoints are created, including the main queue, an expired queue, and a management queue for communicating
        /// back to the turnout coordinator.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="busFactoryConfigurator">The bus factory configuration to use a separate endpoint for the control traffic</param>
        /// <param name="queueName">The receive queue name for commands</param>
        /// <param name="configure"></param>
        /// <param name="host">The host on which to configure the endpoint</param>
        public static void TurnoutEndpoint <T>(this IRabbitMqBusFactoryConfigurator busFactoryConfigurator, IRabbitMqHost host, string queueName,
                                               Action <ITurnoutServiceConfigurator <T> > configure)
            where T : class
        {
            string expiredQueueName = $"{queueName}-expired";

            // configure the message expiration endpoint, so it's available at startup
            busFactoryConfigurator.ReceiveEndpoint(host, expiredQueueName, expiredEndpointConfigurator =>
            {
                // configure the turnout management endpoint
                var temporaryQueueName = host.GetTemporaryQueueName("turnout-");
                busFactoryConfigurator.ReceiveEndpoint(host, temporaryQueueName, turnoutEndpointConfigurator =>
                {
                    turnoutEndpointConfigurator.PrefetchCount = 100;
                    turnoutEndpointConfigurator.AutoDelete    = true;
                    turnoutEndpointConfigurator.Durable       = false;

                    turnoutEndpointConfigurator.DeadLetterExchange = expiredQueueName;

                    // configure the input queue endpoint
                    busFactoryConfigurator.ReceiveEndpoint(host, queueName, commandEndpointConfigurator =>
                    {
                        commandEndpointConfigurator.ConfigureTurnoutEndpoints(busFactoryConfigurator, turnoutEndpointConfigurator, expiredEndpointConfigurator,
                                                                              configure);
                    });
                });
            });
        }
Пример #3
0
        /// <summary>
        /// Creates a request client that uses the bus to publish a request.
        /// </summary>
        /// <typeparam name="TRequest">The request type</typeparam>
        /// <typeparam name="TResponse">The response type</typeparam>
        /// <param name="timeout">The timeout before the request is cancelled</param>
        /// <param name="callback">Callback when the request is sent</param>
        /// <param name="ttl">The time that the request will live for</param>
        /// <param name="host"></param>
        /// <param name="publishEndpoint"></param>
        /// <returns></returns>
        public static async Task <IRequestClient <TRequest, TResponse> > CreatePublishRequestClient <TRequest, TResponse>(this IRabbitMqHost host,
                                                                                                                          IPublishEndpoint publishEndpoint, TimeSpan timeout, TimeSpan?ttl = default(TimeSpan?), Action <SendContext <TRequest> > callback = null)
            where TRequest : class
            where TResponse : class
        {
            var endpoint = await host.ConnectReceiveEndpoint(host.GetTemporaryQueueName("response")).ConfigureAwait(false);

            var ready = await endpoint.Ready.ConfigureAwait(false);

            return(new PublishRequestClient <TRequest, TResponse>(publishEndpoint, ready.ReceiveEndpoint, ready.InputAddress, timeout, ttl, callback));
        }
        /// <summary>
        /// Declare a ReceiveEndpoint using a unique generated queue name. This queue defaults to auto-delete
        /// and non-durable. By default all services bus instances include a default receiveEndpoint that is
        /// of this type (created automatically upon the first receiver binding).
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="host"></param>
        /// <param name="configure"></param>
        public static void ReceiveEndpoint(this IRabbitMqBusFactoryConfigurator configurator, IRabbitMqHost host,
                                           Action <IRabbitMqReceiveEndpointConfigurator> configure)
        {
            var queueName = host.GetTemporaryQueueName("receiveEndpoint-");

            configurator.ReceiveEndpoint(host, queueName, x =>
            {
                x.AutoDelete = true;
                x.Durable    = false;

                configure(x);
            });
        }
        /// <summary>
        /// Registers a management endpoint on the bus, which can be used to control
        /// filters and other management control points on the bus.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="host">The host where the endpoint is to be created</param>
        /// <param name="configure">Configure additional values of the underlying receive endpoint</param>
        /// <returns></returns>
        public static IManagementEndpointConfigurator ManagementEndpoint(this IRabbitMqBusFactoryConfigurator configurator,
            IRabbitMqHost host, Action<IRabbitMqReceiveEndpointConfigurator> configure = null)
        {
            if (configurator == null)
                throw new ArgumentNullException(nameof(configurator));
            if (host == null)
                throw new ArgumentNullException(nameof(host));

            var queueName = host.GetTemporaryQueueName("manage-");

            var endpointConfigurator = new RabbitMqReceiveEndpointSpecification(host, queueName)
            {
                AutoDelete = true,
                Durable = false
            };

            configure?.Invoke(endpointConfigurator);

            configurator.AddReceiveEndpointSpecification(endpointConfigurator);

            var managementEndpointConfigurator = new ManagementEndpointConfigurator(endpointConfigurator);

            return managementEndpointConfigurator;
        }
        /// <summary>
        /// Declare a ReceiveEndpoint using a unique generated queue name. This queue defaults to auto-delete
        /// and non-durable. By default all services bus instances include a default receiveEndpoint that is
        /// of this type (created automatically upon the first receiver binding).
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="host"></param>
        /// <param name="configure"></param>
        public static void ReceiveEndpoint(this IRabbitMqBusFactoryConfigurator configurator, IRabbitMqHost host,
            Action<IRabbitMqReceiveEndpointConfigurator> configure)
        {
            var queueName = host.GetTemporaryQueueName("receiveEndpoint-");

            configurator.ReceiveEndpoint(host, queueName, x =>
            {
                x.AutoDelete = true;
                x.Durable = false;

                configure(x);
            });
        }