示例#1
0
        public Subscription SubscribeAsync <T>(AsyncSubscriptionOption <T> subscriptionOption)
        {
            TryConnectBeforeSubscribing();
            Func <IModel, IBasicConsumer> createConsumer = channel =>
                                                           _consumerManager.CreateAsyncConsumer(channel,
                                                                                                subscriptionOption.SubscriptionName,
                                                                                                subscriptionOption.MessageHandler,
                                                                                                subscriptionOption.BatchSize <= 0
                                                                                   ? (ushort)1
                                                                                   : subscriptionOption.BatchSize);

            var queueName    = (subscriptionOption.RouteFinder ?? _routeFinder).FindQueueName <T>(subscriptionOption.SubscriptionName);
            var prefetchSize = GetProperPrefetchSize(subscriptionOption.QueuePrefetchSize);

            return(CreateSubscription(subscriptionOption.SubscriptionName, queueName, createConsumer, prefetchSize));
        }
示例#2
0
        public void SubscribeAsync <T>(string subscriptionName, Action <T> onReceiveMessage, ushort?batchSize)
        {
            TryConnectBeforeSubscribing();
            Func <IModel, string, IBasicConsumer> createConsumer = (channel, consumerTag) => _consumerManager.CreateAsyncConsumer(channel, subscriptionName, onReceiveMessage, batchSize);

            CreateSubscription <T>(subscriptionName, createConsumer);
        }