private void StartConsumer() { Task.Run(() => { using (var channel = _modelFactory.CreateModel()) { var queueName = _queueNameFactory(); var routingConfig = new RoutingConfig(queueName); var queueConfig = new QueueConfig(queueName, routingConfig, _exchangeConfig, false, true, true, null); if (_declareQueue) { channel.DeclareAndBindQueue(queueConfig); } var consumer = new EventingBasicConsumer(channel); consumer.Received += (obj, evtArgs) => { var correlationId = new Guid(evtArgs.BasicProperties.CorrelationId); _msgsReceived.Add(correlationId, evtArgs); }; channel.BasicConsume(queueName, true, consumer); _stopConsumer.Wait(); } }); // Allow half a second for consumer to start Thread.Sleep(500); }
public QueueConfig(string name, RoutingConfig routingConfig, ExchangeConfig exchange, bool durable, bool exclusive, bool autoDelete, IDictionary <string, object> args) { Exchange = exchange; Name = name; Durable = durable; Exclusive = exclusive; AutoDelete = autoDelete; Args = args; RoutingConfig = routingConfig; }
public Task <bool> VerifyMessageReceived <T>(Func <T, bool> verify, Guid correlationId, int millisecondsTimeout) where T : class { var t = Task.Run(() => { var resetEvent = new ManualResetEventSlim(false); var verified = false; using (var channel = _modelFactory.CreateModel()) { var queueName = _queueNameFactory(); var routingConfig = new RoutingConfig(queueName); var queueConfig = new QueueConfig(queueName, routingConfig, _exchange, false, true, true, null); if (_declareQueue) { channel.DeclareAndBindQueue(queueConfig); } var consumer = new EventingBasicConsumer(channel); consumer.Received += (obj, evtArgs) => { if (correlationId == new Guid(evtArgs.BasicProperties.CorrelationId)) { var msg = _serializerFactory.DeserializeTo <T>(evtArgs); verified = verify(msg); resetEvent.Set(); } }; channel.BasicConsume(queueName, true, consumer); resetEvent.Wait(millisecondsTimeout); } return(verified); }); // Allow half a second for consumer to start Thread.Sleep(500); return(t); }
public QueueConfig(string name, RoutingConfig routingConfig, ExchangeConfig exchange) : this(name, routingConfig, exchange, true, false, false, null) { }
public QueueConfig(string name, RoutingConfig routingConfig) : this(name, routingConfig, ExchangeConfig.Default) { }