public RabbitConsumerTests() { serviceProvider = FakeConfig.BuildServiceProvider(); serializer = serviceProvider.GetRequiredServiceByName <ISerializer>(FakeConfig.Options.SerializationType); this.consumer = new RabbitConsumer(serviceProvider, FakeConfig.ProviderName, serializer); this.eventProcessor = new Mock <IEventProcessor>(); this.consumeOptions = new RabbitConsumeOptions(); }
public Task Subscribe(string queue, string exchange, IEventProcessor processor, RabbitConsumeOptions options) { this.Exchange = exchange; this.Queue = queue; this.Processor = processor; this.Options = options; lock (this._channel) { //Subscription processing this._channel.Model.ExchangeDeclare(this.Exchange, ExchangeType.Direct, true); this._channel.Model.QueueDeclare(this.Queue, true, false, false, null); this._channel.Model.QueueBind(this.Queue, this.Exchange, this.Exchange); this._channel.Model.BasicQos(0, options.OneFetchCount, false); this._channel.Model.CallbackException += Channel_CallbackException; //Consumer reports in the channel var basicConsumer = new EventingBasicConsumer(this._channel.Model); basicConsumer.Received += async(ch, ea) => { await Process(ea); }; basicConsumer .HandleBasicConsumeOk(this._channel.Model.BasicConsume(this.Queue, options.AutoAck, basicConsumer)); } return(Task.CompletedTask); }