Exemple #1
0
 public static IRabbitExchange DeclareExchange(this IRabbitChannel source, string name, RabbitExchangeType exchangeType)
 {
     return(source.DeclareExchange(name, new     ExchangeOptions()
     {
         ExchangeType = exchangeType,
         // defaults	from the original api:
         Durable = false,
         AutoDelete = false
     }));
 }
Exemple #2
0
        public RabbitProducer(IServiceProvider serviceProvider, string providerName, ISerializer serializer)
        {
            this.providerName     = providerName;
            this._serviceProvider = serviceProvider;
            this._serializer      = serializer;
            this._logger          = this._serviceProvider.GetRequiredService <ILogger <RabbitProducer> >();
            var channelFactory = serviceProvider.GetRequiredServiceByName <IRabbitChannelFactory>(providerName);

            this._channel = channelFactory.GetChannel();
        }
Exemple #3
0
        public RabbitConsumer(IServiceProvider serviceProvider, string providerName, ISerializer serializer)
        {
            this.providerName           = providerName;
            this._serviceProvider       = serviceProvider;
            this._serializer            = serializer;
            this._internalConfiguration = serviceProvider.GetRequiredService <IInternalConfiguration>();
            this._logger = serviceProvider.GetRequiredService <ILogger <RabbitConsumer> >();
            var _channelFactory = serviceProvider.GetRequiredServiceByName <IRabbitChannelFactory>(this.providerName);

            this._channel = _channelFactory.GetChannel();
        }
Exemple #4
0
 private void WhenCreateChannel_ConnectionClosed()
 {
     try
     {
         channel = this.connection.CreateChannel();
     }
     catch (Exception ex)
     {
         this.exception = ex;
     }
 }
Exemple #5
0
        public async Task <IRabbitChannel> GetOrEstablishChannelAsync()
        {
            if (channel != null)
            {
                return(channel);
            }

            await semaphore.WaitAsync();

            IsConnecting = true;

            // check again as another task may have established the channel while we awaited the semaphore
            if (channel != null)
            {
                IsConnecting = false;
                return(channel);
            }

            try
            {
                connection = RabbitSetupSetting.GetConnection(options);
                connection.CallbackException       += ConnectionCallbackExceptionHandler;
                connection.ConnectionRecoveryError += ConnectionRecoveryErrorHandler;

                var model = RabbitSetupSetting.GetChannel(connection);
                channel = new RabbitChannel(model, options.Endpoint.Hostname);

                RabbitSetupSetting.StartExchanges(model, options.Exchanges.Values);

                return(channel);
            }
            catch (BrokerUnreachableException)
            {
                //retryTimer.Reset(TimeSpan.FromSeconds(5));
                return(null);
            }
            finally
            {
                IsConnecting = false;
                semaphore.Release();
            }
        }
Exemple #6
0
 public static IRabbitQueueBinding Bind(this IRabbitChannel source,
                                        string exchange, string queue,
                                        string routingKeyOrFilter)
 {
     return((source as IRabbitChannelInternal).BindInternal(false, queue, exchange, routingKeyOrFilter));
 }
Exemple #7
0
 private void WhenCreateChannel()
 {
     channel = this.connection.CreateChannel();
 }