Beispiel #1
0
        /// <summary>
        /// Default library entry point
        /// </summary>
        /// <param name="connectionFactory"></param>
        /// <param name="consumerContainer"></param>
        /// <param name="exchangeResolver"></param>
        /// <param name="serializer"></param>
        /// <param name="idGenerator"></param>
        /// <param name="sequenceGenerator"></param>
        /// <param name="options"> </param>
        public RogerBus(IConnectionFactory connectionFactory,
                        IConsumerContainer consumerContainer = null,
                        IExchangeResolver exchangeResolver   = null,
                        IMessageSerializer serializer        = null,
                        IIdGenerator idGenerator             = null,
                        ISequenceGenerator sequenceGenerator = null,
                        RogerOptions options = null)
        {
            aggregator        = new Aggregator();
            reconnectionTimer = new SystemThreadingTimer();
            connection        = new ReliableConnection(connectionFactory, reconnectionTimer, aggregator);

            consumerContainer = consumerContainer.Or(new EmptyConsumerContainer());
            exchangeResolver  = exchangeResolver.Or(new AttributeExchangeResolver());
            serializer        = serializer.Or(new ProtoBufNetSerializer());
            idGenerator       = idGenerator.Or(new RandomIdGenerator());
            sequenceGenerator = sequenceGenerator.Or(new ByMessageHirarchyRootSequenceGenerator());
            options           = options.Or(new RogerOptions());

            publishModules.Add(new BasicReturnModule());

            if (options.UsePublisherConfirms)
            {
                publishModules.AddFirst(new PublisherConfirmsModule(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)));
            }

            var queueFactory = new DefaultQueueFactory(true,
                                                       false,
                                                       false,
                                                       options.QueueUnusedTimeout,
                                                       options.MessageTimeToLiveOnQueue,
                                                       options.QueueName);

            Filters.Add(new ResequencingDeduplicationFilter());

            consumer = new DefaultConsumingProcess(idGenerator,
                                                   exchangeResolver,
                                                   serializer,
                                                   new DefaultMessageTypeResolver(),
                                                   consumerContainer,
                                                   Filters,
                                                   queueFactory,
                                                   new AlwaysSuccessConsumerInvoker(),
                                                   options,
                                                   aggregator);

            publisher = new QueueingPublishingProcess(idGenerator,
                                                      sequenceGenerator,
                                                      exchangeResolver,
                                                      serializer,
                                                      new DefaultMessageTypeResolver(),
                                                      publishModules,
                                                      aggregator);


            aggregator.Subscribe(this);
        }