private Subscription CreateSubscription <T>(string subscriptionName, Func <IModel, string, IBasicConsumer> createConsumer) { var subscription = new Subscription { SubscriptionName = subscriptionName }; var id = Guid.NewGuid(); Action subscriptionAction = () => { subscription.QueueName = _routeFinder.FindQueueName <T>(subscriptionName); subscription.ConsumerTag = string.Format("{0}-{1}", subscriptionName, Guid.NewGuid()); var channel = _connection.CreateChannel(); channel.ModelShutdown += (c, reason) => { RaiseConsumerDisconnectedEvent(subscription); TryReconnect(c, id, reason); }; if (Global.PreFetchSize <= ushort.MaxValue) { channel.BasicQos(0, (ushort)Global.PreFetchSize, false); } else { _watcher.WarnFormat("The prefetch size is too high {0}, maximum {1}, the queue will prefetch all the msgs", Global.PreFetchSize, ushort.MaxValue); } _createdChannels.Add(channel); subscription.SetChannel(channel); var consumer = createConsumer(channel, subscription.ConsumerTag); if (consumer is DefaultBasicConsumer) { (consumer as DefaultBasicConsumer).ConsumerTag = subscription.ConsumerTag; } //NOTE: The message will still be on the Unacknowledged list until it's processed and the method // DoAck is call. channel.BasicConsume(subscription.QueueName, false /* noAck, must be false */, subscription.ConsumerTag, consumer); _watcher.InfoFormat("Subscribed to: {0} with subscriptionName: {1}", subscription.QueueName, subscription.SubscriptionName); }; _subscribeActions[id] = subscriptionAction; TrySubscribe(subscriptionAction); return(subscription); }
public void Setup() { _routeFinder.FindExchangeName <Customer>().Returns("Exchange.Customer"); _routeFinder.FindQueueName <Customer>(null).ReturnsForAnyArgs("Queue.Customer"); _routeFinder.FindRoutingKey <Customer>().Returns("Customer"); _routeSetupData = new RouteSetupData { RouteFinder = _routeFinder, ExchangeSetupData = new ExchangeSetupData(), QueueSetupData = new QueueSetupData() }; }
public void Setup() { _routeFinder.FindExchangeName <Customer>().Returns("Exchange.Customer"); _routeFinder.FindQueueName <Customer>(null).ReturnsForAnyArgs("Queue.Customer"); _routeFinder.FindRoutingKey <Customer>().Returns("Customer"); _routeSetupData = new RouteSetupData { RouteFinder = _routeFinder, ExchangeSetupData = new ExchangeSetupData(), QueueSetupData = new QueueSetupData { AutoExpire = 10000, MessageTimeToLive = 10000000 } }; }