Exemplo n.º 1
0
        public void TransferToBus(IAdvancedBus advancedBus)
        {
            var rebusEvents = advancedBus.Events;

            if (MessageSent != null)
            {
                foreach (var listener in MessageSent.GetInvocationList().Cast<MessageSentEventHandler>())
                {
                    rebusEvents.MessageSent += listener;
                }
            }

            if (BeforeMessage != null)
            {
                foreach (var listener in BeforeMessage.GetInvocationList().Cast<BeforeMessageEventHandler>())
                {
                    rebusEvents.BeforeMessage += listener;
                }
            }

            if (AfterMessage != null)
            {
                foreach (var listener in AfterMessage.GetInvocationList().Cast<AfterMessageEventHandler>())
                {
                    rebusEvents.AfterMessage += listener;
                }
            }

            if (BeforeTransportMessage != null)
            {
                foreach (var listener in BeforeTransportMessage.GetInvocationList().Cast<BeforeTransportMessageEventHandler>())
                {
                    rebusEvents.BeforeTransportMessage += listener;
                }
            }

            if (AfterTransportMessage != null)
            {
                foreach (var listener in AfterTransportMessage.GetInvocationList().Cast<AfterTransportMessageEventHandler>())
                {
                    rebusEvents.AfterTransportMessage += listener;
                }
            }

            if (PoisonMessage != null)
            {
                foreach (var listener in PoisonMessage.GetInvocationList().Cast<PoisonMessageEventHandler>())
                {
                    rebusEvents.PoisonMessage += listener;
                }
            }

            if (UncorrelatedMessage != null)
            {
                foreach (var listener in UncorrelatedMessage.GetInvocationList().Cast<UncorrelatedMessageEventHandler>())
                {
                    rebusEvents.UncorrelatedMessage += listener;
                }
            }
        }
        public when_sending_property_request_to_lace_entry_point()
        {
            _bus = BusFactory.WorkflowBus();

            _request = new PropertyRequestBuilder().ForPropertySources();
            _entryPoint = new EntryPointService(_bus);
        }
        public when_initalizing_lace_source_chain_for_vin_rgt_vin_rgt_search()
        {

            _command = BusFactory.WorkflowBus();
            _request = new VinRequestBuilder().ForRgtAndRgtVin();
            _buildSourceChain = new CreateSourceChain();
        }
        public when_sending_director_request_to_lace_entry_point()
        {
            _bus = BusFactory.WorkflowBus();

            _request = new DirectorRequestBuilder().ForLightstoneDirector();
            _entryPoint = new EntryPointService(_bus);
        }
        public void Start()
        {
            _bus = BusFactory.CreateAdvancedBus(ConfigurationReader.WorkflowSender);
            var senderQueue = _bus.QueueDeclare("DataPlatform.DataProvider.Sender");
            var senderExchange = _bus.ExchangeDeclare("DataPlatform.DataProvider.Sender", ExchangeType.Fanout);
            _bus.Bind(senderExchange, senderQueue, string.Empty);

            var receiverQueue = _bus.QueueDeclare("DataPlatform.DataProvider.Receiver");
            var receiverExchange = _bus.ExchangeDeclare("DataPlatform.DataProvider.Receiver", ExchangeType.Fanout);
            _bus.Bind(receiverExchange, receiverQueue, string.Empty);

            _bus.Consume(senderQueue, x => x
                .Add<SendRequestToDataProviderCommand>(
                    (message, info) => new SenderCauseFailureConsumers<SendRequestToDataProviderCommand>(message))
                .Add<GetResponseFromDataProviderCommmand>(
                    (message, info) => new SenderCauseFailureConsumers<GetResponseFromDataProviderCommmand>(message))
                .Add<CreateTransactionCommand>(
                    (message, info) => new SenderCauseFailureConsumers<CreateTransactionCommand>(message))
                .Add<ReceiveEntryPointRequest>(
                    (message, info) => new SenderCauseFailureConsumers<ReceiveEntryPointRequest>(message))
                .Add<ReturnEntryPointResponse>(
                    (message, info) => new SenderCauseFailureConsumers<ReturnEntryPointResponse>(message))
                .Add<RaisingSecurityFlagCommand>(
                    (message, info) => new SenderCauseFailureConsumers<RaisingSecurityFlagCommand>(message))
                .Add<ConfiguringDataProviderCommand>(
                    (message, info) => new SenderCauseFailureConsumers<ConfiguringDataProviderCommand>(message))
                .Add<TransformingDataProviderResponseCommand>(
                    (message, info) => new SenderCauseFailureConsumers<TransformingDataProviderResponseCommand>(message))
                .Add<ErrorInDataProviderCommand>(
                    (message, info) => new SenderCauseFailureConsumers<ErrorInDataProviderCommand>(message))
                .Add<StartingCallCommand>(
                    (message, info) => new SenderCauseFailureConsumers<StartingCallCommand>(message))
                .Add<EndingCallCommand>((message, info) => new SenderCauseFailureConsumers<EndingCallCommand>(message)));

            _bus.Consume(receiverQueue, x => x
                .Add<RequestToDataProvider>(
                    (message, info) => new ReceiverCauseFailureConsumers<RequestToDataProvider>(message))
                .Add<EntryPointReceivedRequest>(
                    (message, info) => new ReceiverCauseFailureConsumers<EntryPointReceivedRequest>(message))
                .Add<ResponseFromDataProvider>(
                    (message, info) => new ReceiverCauseFailureConsumers<ResponseFromDataProvider>(message))
                .Add<EntryPointReturnedResponse>(
                    (message, info) => new ReceiverCauseFailureConsumers<EntryPointReturnedResponse>(message))
                //.Add<BillTransactionMessage>(
                //    (message, info) => new ReceiverConsumers<BillTransactionMessage>(message))
                .Add<SecurityFlagRaised>(
                    (message, info) => new ReceiverCauseFailureConsumers<SecurityFlagRaised>(message))
                .Add<DataProviderCallEnded>(
                    (message, info) => new ReceiverCauseFailureConsumers<DataProviderCallEnded>(message))
                .Add<DataProviderCallStarted>(
                    (message, info) => new ReceiverCauseFailureConsumers<DataProviderCallStarted>(message))
                .Add<DataProviderError>(
                    (message, info) => new ReceiverCauseFailureConsumers<DataProviderError>(message))
                .Add<DataProviderResponseTransformed>(
                    (message, info) => new ReceiverCauseFailureConsumers<DataProviderResponseTransformed>(message))
                .Add<DataProviderConfigured>(
                    (message, info) => new ReceiverCauseFailureConsumers<DataProviderConfigured>(message)));

            _log.DebugFormat("Data Provider Command Processor Service Started");
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            connection = mockBuilder.Connection;
            advancedBus = mockBuilder.Bus.Advanced;
        }
        public when_inititializing_lace_source_chain_for_rgt_vin_vin12()
        {

            _command = BusFactory.WorkflowBus();
            _request = new VinRequestBuilder().ForRgtVin12VinNumber();
            _buildSourceChain = new CreateSourceChain();
        }
 public IExchange DeclareExchange(IAdvancedBus advancedBus, Type messageType, string exchangeType)
 {
     var conventions = advancedBus.Container.Resolve<IConventions>();
     var messageVersions = new MessageVersionStack( messageType );
     var publishExchange = DeclareVersionedExchanges( advancedBus, conventions, messageVersions, exchangeType );
     return publishExchange;
 }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            exchange = advancedBus.ExchangeDeclare("my_exchange", ExchangeType.Direct, passive:true);
        }
        public when_inititializing_lace_source_chain_for_MisMatchlicensePlate_number_search()
        {

            _command = BusFactory.WorkflowBus();
            _request = new LicensePlateRequestBuilder().ForAllSourcesWithMisMatchLicensePlate();
            _buildSourceChain = new CreateSourceChain();
        }
 public MessagePublisher(IAdvancedBus bus, ILogger logger, IExchange exchange, IQueue queue)
 {
     _bus = bus;
     _logger = logger;
     _exchange = exchange;
     _queue = queue;
 }
        public when_sending_company_request_to_lace_entry_point()
        {
            _bus = BusFactory.WorkflowBus();

            _request = new CompanyRequestBuilder().ForLightstoneCompany();
            _entryPoint = new EntryPointService(_bus);
        }
Exemplo n.º 13
0
        public void SetUp()
        {
            var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
            {
                HostName = "localhost",
                VirtualHost = "/",
                UserName = "******",
                Password = "******"
            });

            var serializer = new JsonSerializer();
            var logger = new ConsoleLogger();
            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);
            var conventions = new Conventions();

            advancedBus = new RabbitAdvancedBus(
                connectionFactory,
                TypeNameSerializer.Serialize,
                serializer,
                new QueueingConsumerFactory(logger, consumerErrorStrategy),
                logger,
                CorrelationIdGenerator.GetCorrelationId,
                conventions);

            while (!advancedBus.IsConnected)
            {
                Thread.Sleep(10);
            }
        }
        public void Start()
        {
            _log.DebugFormat("Started billing run service");

            var container = new WindsorContainer().Install(
                new NHibernateInstaller(),
                new WindsorInstaller(),
                new CacheProviderInstaller(),
                new RepositoryInstaller(),
                new AutoMapperInstaller(),
                new ConsumerInstaller(),
                new BusInstaller(),
                new PublishReportQueueInstaller(),
                new PivotInstaller(),
                new ReportBuilderInstaller(),
                new NotificationInstaller());

            try
            {
                advancedBus = container.Resolve<IAdvancedBus>();
                var q = advancedBus.QueueDeclare("DataPlatform.Transactions.BillingRun");

                advancedBus.Consume(q, x => x
                    .Add<BillingMessage>((message, info) => new TransactionConsumer<BillingMessage>(message, container)));
            }
            catch (Exception e)
            {
                this.Error(() => e.Message);
            }
            _log.DebugFormat("Billing run service started");
        }
        public void Start()
        {
            _log.DebugFormat("Started billing service");

            var container = new WindsorContainer().Install(
                new NHibernateInstaller(),
                new WindsorInstaller(),
                new CacheProviderInstaller(),
                new RepositoryInstaller(),
                new AutoMapperInstaller(),
                new ConsumerInstaller(),
                new BusInstaller(),
                new PublishReportQueueInstaller(),
                new PivotInstaller(),
                new ScheduleInstaller());

            advancedBus = container.Resolve<IAdvancedBus>();
            var q = advancedBus.QueueDeclare("DataPlatform.Transactions.Billing");
            
            advancedBus.Consume(q, x => x
                .Add<InvoiceTransactionCreated>((message, info) => new TransactionConsumer<InvoiceTransactionCreated> (message, container))
                .Add<UserMessage>((message, info) => new TransactionConsumer<UserMessage> (message, container))
                .Add<CustomerMessage>((message, info) => new TransactionConsumer<CustomerMessage>(message, container))
                .Add<ClientMessage>((message, info) => new TransactionConsumer<ClientMessage>(message, container))
                .Add<PackageMessage>((message, info) => new TransactionConsumer<PackageMessage>(message, container))
                .Add<ContractMessage>((message, info) => new TransactionConsumer<ContractMessage>(message, container))
                .Add<TransactionRequestMessage>((message, info) => new TransactionConsumer<TransactionRequestMessage>(message, container))
                .Add<TransactionRequestCleanupMessage>((message, info) => new TransactionConsumer<TransactionRequestCleanupMessage>(message, container)));

            _log.DebugFormat("Billing service started");
        }
        public when_inititializing_lace_source_chain_for_vin_rgt_mm_code_search()
        {

            _command = BusFactory.WorkflowBus();
            _request = new LicensePlateMmCodeRequestBuilder().ForIvidRgtVinMmCode();
            _buildSourceChain = new CreateSourceChain();
        }
 public Task<IExchange> DeclareExchangeAsync(IAdvancedBus advancedBus, string exchangeName, string exchangeType)
 {
     return exchangeNames.AddOrUpdate(
         exchangeName,
         name => advancedBus.ExchangeDeclareAsync(name, exchangeType),
         (_, exchange) => exchange);
 }
        static GenerateCorrespondingVoucherBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            RequestExchange = new ExchangePublisher<GenerateCorrespondingVoucherRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.GenerateCorrespondingVoucherResponseQueueName);
        }
Exemplo n.º 19
0
        static CheckThirdPartyBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            RequestExchange = new ExchangePublisher<CheckThirdPartyBatchRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.CheckThirdPartyResponseQueueName);
        }
Exemplo n.º 20
0
        static OutboundServiceBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationManager.ConnectionStrings["rabbitMQ"].ConnectionString);

            RequestPublisher = new ExchangePublisher<CreateImageExchangeFileRequest>(Bus);
            RequestPublisher.Declare("lombard.service.outclearings.createimageexchangefile.request");
            ResponseQueue = Bus.QueueDeclare("lombard.service.outclearings.createimageexchangefile.response.queue");
        }
Exemplo n.º 21
0
        static ValidateCodelineBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            RequestExchange = new ExchangePublisher<ValidateBatchCodelineRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.ValidateCodelineResponseQueueName);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var queue = new Topology.Queue("my_queue", false);
            advancedBus.QueueDelete(queue);
        }
Exemplo n.º 23
0
        static AutoReadCarBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            InboundExchange = new ExchangePublisher<RecogniseBatchCourtesyAmountRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.OutboundQueueName);
        }
Exemplo n.º 24
0
        static GetVouchersInformationBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            ResponseExchange = new ExchangePublisher<GetVouchersInformationResponse>(Bus);

            RequestQueue = Bus.QueueDeclare(ConfigurationHelper.GetPoolVouchersQueueName);
        }
Exemplo n.º 25
0
 public Initialize(ICollection<IPointToLaceProvider> responses, ICollection<IPointToLaceRequest> request, IAdvancedBus bus,
     IBuildSourceChain buildSourceChain)
 {
     _request = request;
     _bus = bus;
     DataProviderResponses = responses;
     _buildSourceChain = buildSourceChain;
 }
Exemplo n.º 26
0
        static VifBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            RequestExchange = new ExchangePublisher<SendBatchValueInstructionFileRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.VifResponseQueueName);
        }
Exemplo n.º 27
0
        static CorrectTransactionBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            RequestExchange = new ExchangePublisher<CorrectBatchTransactionRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.CorrectTransactionResponseQueueName);
        }
Exemplo n.º 28
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var exchange = new Exchange("my_exchange");
            advancedBus.ExchangeDelete(exchange);
        }
 public when_building_lace_source_chain_for_drivers_license_decryption()
 {
     _bus = Lace.Test.Helper.Builders.Buses.BusFactory.WorkflowBus();
     _request = new DriversLicenseRequestBuilder().ForDriversLicenseScan();
     _buildSourceChain = new FakeSourceChain();
     //_buildSourceChain = new FakeSourceChain(_request.GetFromRequest<IPointToLaceRequest>().Package);
     //_buildSourceChain.Build();
 }
Exemplo n.º 30
0
        static CreateAdjustmentLettersBus()
        {
            Bus = MessageBusFactory.CreateBus(ConfigurationHelper.RabbitMqConnectionString);

            RequestExchange = new ExchangePublisher<CreateBatchAdjustmentLettersRequest>(Bus);

            Queue = Bus.QueueDeclare(ConfigurationHelper.ResponseQueueName);
        }
Exemplo n.º 31
0
        public IExchange DeclareExchange(IAdvancedBus advancedBus, Type messageType, string exchangeType)
        {
            var conventions        = advancedBus.Container.Resolve <IConventions>();
            var sourceExchangeName = conventions.ExchangeNamingConvention(messageType);
            var sourceExchange     = DeclareExchange(advancedBus, sourceExchangeName, exchangeType);
            var interfaces         = messageType.GetInterfaces();

            foreach (var @interface in interfaces)
            {
                var destinationExchangeName = conventions.ExchangeNamingConvention(@interface);
                var destinationExchange     = DeclareExchange(advancedBus, destinationExchangeName, exchangeType);
                if (destinationExchange != null)
                {
                    advancedBus.Bind(sourceExchange, destinationExchange, "#");
                }
            }

            return(sourceExchange);
        }
Exemplo n.º 32
0
        /// <summary>
        /// Stop MQ Server
        /// </summary>
        public void Disconnect()
        {
            _tickconsumer.OnCancel();
            _tokenSource.Cancel();
            //_dataConsumerTask.Dispose();
            //_barTask.Dispose();

            _easyNetQBus.Dispose();
            _easyNetQBus = null;

            _rabbitMqTickChannel.QueueDelete("simulated.tickdata.queue");

            _rabbitMqTickChannel.Close();
            _rabbitMqTickConnection.Close();
            _rabbitMqTickBus = null;

            //_rabbitMqBarChannel.Close();
            //_rabbitMqBarConnection.Close();
        }
Exemplo n.º 33
0
 public ExternalScheduler(
     IAdvancedBus advancedBus,
     IConventions conventions,
     ITypeNameSerializer typeNameSerializer,
     IExchangeDeclareStrategy exchangeDeclareStrategy,
     IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
     IMessageSerializationStrategy messageSerializationStrategy
     )
 {
     this.advancedBus             = advancedBus ?? throw new ArgumentNullException(nameof(advancedBus));
     this.conventions             = conventions ?? throw new ArgumentNullException(nameof(conventions));
     this.typeNameSerializer      = typeNameSerializer ?? throw new ArgumentNullException(nameof(typeNameSerializer));
     this.exchangeDeclareStrategy = exchangeDeclareStrategy ??
                                    throw new ArgumentNullException(nameof(exchangeDeclareStrategy));
     this.messageDeliveryModeStrategy = messageDeliveryModeStrategy ??
                                        throw new ArgumentNullException(nameof(messageDeliveryModeStrategy));
     this.messageSerializationStrategy = messageSerializationStrategy ??
                                         throw new ArgumentNullException(nameof(messageSerializationStrategy));
 }
Exemplo n.º 34
0
        private void TryConnect()
        {
            if (IsConnected)
            {
                return;
            }

            var policy = Policy.Handle <EasyNetQException>()
                         .Or <BrokerUnreachableException>()
                         .WaitAndRetry(3, retryAttempt =>
                                       TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

            policy.Execute(() =>
            {
                _bus         = RabbitHutch.CreateBus(_connectionString);
                _advancedBus = _bus.Advanced;
                _advancedBus.Disconnected += OnDisconnect;
            });
        }
Exemplo n.º 35
0
        /// <summary>
        ///     Creates DefaultPubSub
        /// </summary>
        /// <param name="configuration">The configuration</param>
        /// <param name="conventions">The conventions</param>
        /// <param name="exchangeDeclareStrategy">The exchange declare strategy</param>
        /// <param name="messageDeliveryModeStrategy">The message delivery mode strategy</param>
        /// <param name="advancedBus">The advanced bus</param>
        public DefaultPubSub(
            ConnectionConfiguration configuration,
            IConventions conventions,
            IExchangeDeclareStrategy exchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IAdvancedBus advancedBus
            )
        {
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(exchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(messageDeliveryModeStrategy, "messageDeliveryModeStrategy");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");

            this.configuration               = configuration;
            this.conventions                 = conventions;
            this.exchangeDeclareStrategy     = exchangeDeclareStrategy;
            this.messageDeliveryModeStrategy = messageDeliveryModeStrategy;
            this.advancedBus                 = advancedBus;
        }
Exemplo n.º 36
0
        /// <summary>
        ///     Creates RabbitBus
        /// </summary>
        /// <param name="advanced">The advanced bus</param>
        /// <param name="pubSub">The pub-sub</param>
        /// <param name="rpc">The rpc</param>
        /// <param name="sendReceive">The send-receive</param>
        /// <param name="scheduler">The scheduler</param>
        public RabbitBus(
            IAdvancedBus advanced,
            IPubSub pubSub,
            IRpc rpc,
            ISendReceive sendReceive,
            IScheduler scheduler
            )
        {
            Preconditions.CheckNotNull(advanced, "advanced");
            Preconditions.CheckNotNull(pubSub, "pubSub");
            Preconditions.CheckNotNull(rpc, "rpc");
            Preconditions.CheckNotNull(sendReceive, "sendReceive");
            Preconditions.CheckNotNull(scheduler, "scheduler");

            Advanced    = advanced;
            PubSub      = pubSub;
            Rpc         = rpc;
            SendReceive = sendReceive;
            Scheduler   = scheduler;
        }
Exemplo n.º 37
0
        public SchedulerServiceTests()
        {
            bus         = Substitute.For <IBus>();
            advancedBus = Substitute.For <IAdvancedBus>();

            bus.IsConnected.Returns(true);
            bus.Advanced.Returns(advancedBus);

            scheduleRepository = Substitute.For <IScheduleRepository>();

            schedulerService = new SchedulerService(
                bus,
                scheduleRepository,
                new SchedulerServiceConfiguration
            {
                PublishIntervalSeconds  = 1,
                PurgeIntervalSeconds    = 1,
                EnableLegacyConventions = false
            });
        }
Exemplo n.º 38
0
        public Rpc(
            IAdvancedBus advancedBus,
            IEventBus eventBus,
            IConventions conventions,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IConnectionConfiguration configuration)
        {
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(configuration, "configuration");

            this.advancedBus = advancedBus;
            this.conventions = conventions;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.configuration = configuration;

            eventBus.Subscribe <ConnectionCreatedEvent>(OnConnectionCreated);
        }
Exemplo n.º 39
0
        public SchedulerServiceTests()
        {
            bus         = Substitute.For <IBus>();
            advancedBus = Substitute.For <IAdvancedBus>();

            bus.IsConnected.Returns(true);
            bus.Advanced.Returns(advancedBus);

            scheduleRepository = Substitute.For <IScheduleRepository>();

            schedulerService = new SchedulerService(
                bus,
                Substitute.For <IEasyNetQLogger>(),
                scheduleRepository,
                new SchedulerServiceConfiguration
            {
                PublishIntervalSeconds = 1,
                PurgeIntervalSeconds   = 1
            });
        }
        public async Task <IExchange> DeclareExchangeAsync(IAdvancedBus advancedBus, string exchangeName, string exchangeType)
        {
            IExchange exchange;

            if (exchanges.TryGetValue(exchangeName, out exchange))
            {
                return(exchange);
            }
            using (await asyncLock.AcquireAsync().ConfigureAwait(false))
            {
                if (exchanges.TryGetValue(exchangeName, out exchange))
                {
                    return(exchange);
                }
                exchange = await advancedBus.ExchangeDeclareAsync(exchangeName, exchangeType).ConfigureAwait(false);

                exchanges[exchangeName] = exchange;
                return(exchange);
            }
        }
Exemplo n.º 41
0
        private void TryConnect()
        {
            if (IsConnected)
            {
                return;
            }

            var policy = Policy.Handle <EasyNetQException>()
                         .Or <BrokerUnreachableException>()
                         .WaitAndRetry(3, retryAttempt =>
                                       TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

            //melhorando a resiliencia para quando o serviço de fila cair (event quie)
            policy.Execute(() =>
            {
                _bus         = RabbitHutch.CreateBus(_connectionString);
                _advancedBus = _bus.Advanced;
                _advancedBus.Disconnected += OnDisconnect;
            });
        }
Exemplo n.º 42
0
        public void SetUp()
        {
            bus         = MockRepository.GenerateStub <IBus>();
            advancedBus = MockRepository.GenerateStub <IAdvancedBus>();

            bus.Stub(x => x.IsConnected).Return(true);
            bus.Stub(x => x.Advanced).Return(advancedBus);

            scheduleRepository = MockRepository.GenerateStub <IScheduleRepository>();

            schedulerService = new SchedulerService(
                bus,
                MockRepository.GenerateStub <IEasyNetQLogger>(),
                scheduleRepository,
                new SchedulerServiceConfiguration
            {
                PublishIntervalSeconds = 1,
                PurgeIntervalSeconds   = 1
            });
        }
        private IExchange DeclareVersionedExchanges(IAdvancedBus advancedBus, IConventions conventions, MessageVersionStack messageVersions, string exchangeType)
        {
            // This works because the message version stack is LIFO from most superseded message type to the actual message type
            IExchange destinationExchange = null;

            while (!messageVersions.IsEmpty())
            {
                var messageType    = messageVersions.Pop();
                var exchangeName   = conventions.ExchangeNamingConvention(messageType);
                var sourceExchange = DeclareExchange(advancedBus, exchangeName, exchangeType);

                if (destinationExchange != null)
                {
                    advancedBus.Bind(sourceExchange, destinationExchange, "#");
                }

                destinationExchange = sourceExchange;
            }
            return(destinationExchange);
        }
Exemplo n.º 44
0
        public When_an_exchange_is_declared()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            mockBuilder.NextModel.WhenForAnyArgs(x => x.ExchangeDeclare(null, null, false, false, null))
            .Do(x =>
            {
                arguments = x[4] as IDictionary;
            });

            exchange = advancedBus.ExchangeDeclare(
                "my_exchange",
                ExchangeType.Direct,
                false,
                false,
                true,
                true,
                "my.alternate.exchange");
        }
Exemplo n.º 45
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            mockBuilder.NextModel.Stub(x => x.ExchangeDeclare(null, null, false, false, null))
            .IgnoreArguments()
            .WhenCalled(x =>
            {
                arguments = x.Arguments[4] as IDictionary;
            });

            exchange = advancedBus.ExchangeDeclare(
                "my_exchange",
                ExchangeType.Direct,
                false,
                false,
                true,
                true,
                "my.alternate.exchange");
        }
Exemplo n.º 46
0
        public async Task <IExchange> DeclareExchangeAsync(IAdvancedBus advancedBus, Type messageType, string exchangeType)
        {
            var conventions        = advancedBus.Container.Resolve <IConventions>();
            var sourceExchangeName = conventions.ExchangeNamingConvention(messageType);
            var sourceExchange     = await DeclareExchangeAsync(advancedBus, sourceExchangeName, exchangeType).ConfigureAwait(false);

            var interfaces = messageType.GetInterfaces();

            foreach (var @interface in interfaces)
            {
                var destinationExchangeName = conventions.ExchangeNamingConvention(@interface);
                var destinationExchange     = await DeclareExchangeAsync(advancedBus, destinationExchangeName, exchangeType);

                if (destinationExchange != null)
                {
                    await advancedBus.BindAsync(sourceExchange, destinationExchange, "#").ConfigureAwait(false);
                }
            }

            return(sourceExchange);
        }
Exemplo n.º 47
0
        public RabbitBus(
            IEasyNetQLogger logger,
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IRpc rpc)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(rpc, "rpc");

            this.logger      = logger;
            this.conventions = conventions;
            this.advancedBus = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.rpc = rpc;

            advancedBus.Connected    += OnConnected;
            advancedBus.Disconnected += OnDisconnected;
        }
Exemplo n.º 48
0
        public ExternalScheduler(
            IAdvancedBus advancedBus,
            IConventions conventions,
            ITypeNameSerializer typeNameSerializer,
            IExchangeDeclareStrategy exchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IMessageSerializationStrategy messageSerializationStrategy)
        {
            Preconditions.CheckNotNull(advancedBus, nameof(advancedBus));
            Preconditions.CheckNotNull(conventions, nameof(conventions));
            Preconditions.CheckNotNull(exchangeDeclareStrategy, nameof(exchangeDeclareStrategy));
            Preconditions.CheckNotNull(messageDeliveryModeStrategy, nameof(messageDeliveryModeStrategy));
            Preconditions.CheckNotNull(messageSerializationStrategy, nameof(messageSerializationStrategy));
            Preconditions.CheckNotNull(typeNameSerializer, nameof(typeNameSerializer));

            this.advancedBus                  = advancedBus;
            this.conventions                  = conventions;
            this.typeNameSerializer           = typeNameSerializer;
            this.exchangeDeclareStrategy      = exchangeDeclareStrategy;
            this.messageDeliveryModeStrategy  = messageDeliveryModeStrategy;
            this.messageSerializationStrategy = messageSerializationStrategy;
        }
Exemplo n.º 49
0
        public ExternalScheduler(
            IAdvancedBus advancedBus,
            IConventions conventions,
            ITypeNameSerializer typeNameSerializer,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IMessageSerializationStrategy messageSerializationStrategy)
        {
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(messageDeliveryModeStrategy, "messageDeliveryModeStrategy");
            Preconditions.CheckNotNull(messageSerializationStrategy, "messageSerializationStrategy");
            Preconditions.CheckNotNull(typeNameSerializer, "typeNameSerializer");

            this.advancedBus                    = advancedBus;
            this.conventions                    = conventions;
            this.typeNameSerializer             = typeNameSerializer;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.messageDeliveryModeStrategy    = messageDeliveryModeStrategy;
            this.messageSerializationStrategy   = messageSerializationStrategy;
        }
        /// <summary>
        ///     Creates DeadLetterExchangeAndMessageTtlScheduler
        /// </summary>
        /// <param name="configuration">The configuration</param>
        /// <param name="advancedBus">The advanced bus</param>
        /// <param name="conventions">The conventions</param>
        /// <param name="messageDeliveryModeStrategy">The message delivery mode strategy</param>
        /// <param name="exchangeDeclareStrategy">The exchange declare strategy</param>
        /// <param name="setDeadLetterRoutingKey">Set deadLetterRoutingKey for backward compability</param>
        public DeadLetterExchangeAndMessageTtlScheduler(
            ConnectionConfiguration configuration,
            IAdvancedBus advancedBus,
            IConventions conventions,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IExchangeDeclareStrategy exchangeDeclareStrategy,
            bool setDeadLetterRoutingKey = false
            )
        {
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(messageDeliveryModeStrategy, "messageDeliveryModeStrategy");
            Preconditions.CheckNotNull(exchangeDeclareStrategy, "exchangeDeclareStrategy");

            this.configuration = configuration;
            this.advancedBus   = advancedBus;
            this.conventions   = conventions;
            this.messageDeliveryModeStrategy = messageDeliveryModeStrategy;
            this.exchangeDeclareStrategy     = exchangeDeclareStrategy;
            this.setDeadLetterRoutingKey     = setDeadLetterRoutingKey;
        }
Exemplo n.º 51
0
        public void SetUp()
        {
            bus         = MockRepository.GenerateStub <IBus>();
            advancedBus = MockRepository.GenerateStub <IAdvancedBus>();
            channel     = MockRepository.GenerateStub <IAdvancedPublishChannel>();

            bus.Stub(x => x.IsConnected).Return(true);
            bus.Stub(x => x.Advanced).Return(advancedBus);
            advancedBus.Stub(x => x.OpenPublishChannel()).Return(channel);

            scheduleRepository = MockRepository.GenerateStub <IScheduleRepository>();

            schedulerService = new SchedulerService(
                bus,
                new ConsoleLogger(),
                scheduleRepository,
                new SchedulerServiceConfiguration
            {
                PublishIntervalSeconds = 1,
                PurgeIntervalSeconds   = 1
            });
        }
Exemplo n.º 52
0
        public void SaveBusInstances(IBus bus, IAdvancedBus advancedBus)
        {
            container.Register(
                Component.For <IBus>()
                .Named("bus")
                .LifestyleSingleton()
                .Instance(bus),

                Component.For <IAdvancedBus>()
                .Named("advancedBus")
                .LifestyleSingleton()
                .Instance(advancedBus),

                Component.For <IMessageContext>()
                .UsingFactoryMethod(k => MessageContext.GetCurrent())
                .LifestyleTransient(),

                Component.For <InstanceDisposer>()
                );

            container.Resolve <InstanceDisposer>();
        }
Exemplo n.º 53
0
        public RabbitBus(
            SerializeType serializeType,
            IEasyNetQLogger logger,
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy)
        {
            Preconditions.CheckNotNull(serializeType, "serializeType");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");

            this.serializeType = serializeType;
            this.logger        = logger;
            this.conventions   = conventions;
            this.advancedBus   = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;

            advancedBus.Connected    += OnConnected;
            advancedBus.Disconnected += OnDisconnected;
        }
Exemplo n.º 54
0
        public void TestQueueWay4()
        {
            IAdvancedBus bus = RabbitHutch.CreateBus(ConfigurationAppSetting.RabbitMQHost, reg => reg.Register <IEasyNetQLogger>(log => new Log4NetLogger())).Advanced;
            IExchange    ex  = bus.ExchangeDeclare("JinRi.Notify.Test.TestQueueWay4Ex", "topic");
            IQueue       qu1 = bus.QueueDeclare("JinRi.Notify.Test.TestQueueWay4Queue1");
            IQueue       qu2 = bus.QueueDeclare("JinRi.Notify.Test.TestQueueWay4Queue2");
            IQueue       qu3 = bus.QueueDeclare("JinRi.Notify.Test.TestQueueWay4Queue3");
            IBinding     bi1 = bus.Bind(ex, qu1, "*.0.*");
            IBinding     bi2 = bus.Bind(ex, qu2, "*.1.*");
            IBinding     bi3 = bus.Bind(ex, qu3, "*.2.*");

            for (int i = 0; i < 100; i++)
            {
                int md = i % 3;
                bus.Publish <string>(ex, "a." + md.ToString() + ".b", false, false, new Message <string>(i.ToString()));
            }

            bus.Consume <string>(qu1, (a, b) =>
            {
                Debug.WriteLine(a.Body);
            });
            Thread.Sleep(5000);
        }
Exemplo n.º 55
0
        public Rpc(
            IAdvancedBus advancedBus,
            IEventBus eventBus,
            IConventions conventions,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            ITimeoutStrategy timeoutStrategy)
        {
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(messageDeliveryModeStrategy, "messageDeliveryModeStrategy");
            Preconditions.CheckNotNull(timeoutStrategy, "timeoutStrategy");

            this.advancedBus = advancedBus;
            this.conventions = conventions;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.messageDeliveryModeStrategy    = messageDeliveryModeStrategy;
            this.timeoutStrategy = timeoutStrategy;

            eventBus.Subscribe <ConnectionCreatedEvent>(OnConnectionCreated);
        }
        private void TryConnect()
        {
            if (IsConnected)
            {
                return;
            }

            RetryPolicy policy = Policy.Handle <EasyNetQException>()
                                 .Or <BrokerUnreachableException>()
                                 .WaitAndRetry(3, retryAttempt =>
                                               TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                                               (outcome, timespan, retryCount, context) =>
            {
                Console.WriteLine($"Tentando pela {retryCount} vez!");
            });

            policy.Execute(() =>
            {
                _bus         = RabbitHutch.CreateBus(_connectionString);
                _advancedBus = _bus.Advanced;
                _advancedBus.Disconnected += OnDisconnect;
            });
        }
Exemplo n.º 57
0
        public void Init()
        {
            try
            {
                _waitForMessage.Reset();

                //connect
                Stopwatch w = new Stopwatch();
                w.Start();
                _advancedBus = RabbitHutch.CreateBus(
                    _connectionConfiguration,
                    new AdvancedBusEventHandlers(
                        connected: OnRabbitConnectionStateChanged,
                        disconnected: OnRabbitConnectionStateChanged),
                    RegisterServices
                    ).Advanced;
                w.Stop();
                Console.WriteLine($"Oppkobling: {w.ElapsedMilliseconds} ms");

                //SystemX
                _systemXExchange = GetExchange("exchange.to.SystemX.from.TransMed");
                _systemXQueue    = GetQueue("queue.to.SystemX.from.TransMed");
                _advancedBus.Bind(_systemXExchange, _systemXQueue, "#");

                _transMedExchange = GetExchange("exchange.to.TransMed.from.SystemX");
                _transMedQueue    = GetQueue("queue.to.TransMed.from.SystemX");
                _advancedBus.Bind(_transMedExchange, _transMedQueue, "#");


                _rpc = new SystemXRpc(_advancedBus);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error on init: " + e);
                throw;
            }
        }
Exemplo n.º 58
0
        public IExchange DeclareExchange(IAdvancedBus advancedBus, string exchangeName, string exchangeType)
        {
            IExchange exchange;

            if (exchanges.TryGetValue(exchangeName, out exchange))
            {
                return(exchange);
            }
            semaphore.Wait();
            try
            {
                if (exchanges.TryGetValue(exchangeName, out exchange))
                {
                    return(exchange);
                }
                exchange = advancedBus.ExchangeDeclare(exchangeName, exchangeType);
                exchanges[exchangeName] = exchange;
                return(exchange);
            }
            finally
            {
                semaphore.Release();
            }
        }
    public static async Task ResendErrorsAsync(this IAdvancedBus source, string errorQueueName)
    {
        var errorQueue = await source.QueueDeclareAsync(errorQueueName);

        var message = await source.GetMessageAsync(errorQueue);

        while (message != null)
        {
            var utf8Body       = Encoding.UTF8.GetString(message.Body);
            var error          = JsonConvert.DeserializeObject <Error>(utf8Body);
            var errorBodyBytes = Encoding.UTF8.GetBytes(error.Message);
            var exchange       = await source.ExchangeDeclareAsync(error.Exchange, x =>
            {
                // This can be adjusted to fit the exchange actual configuration
                x.AsDurable(true);
                x.AsAutoDelete(false);
                x.WithType("topic");
            });

            await source.PublishAsync(exchange, error.RoutingKey, true, error.BasicProperties, errorBodyBytes);

            message = await source.GetMessageAsync(errorQueue);
        }
    }
Exemplo n.º 60
0
        public RabbitBus(
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IRpc rpc,
            ISendReceive sendReceive,
            ConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(rpc, "rpc");
            Preconditions.CheckNotNull(sendReceive, "sendReceive");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.conventions = conventions;
            this.advancedBus = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.messageDeliveryModeStrategy    = messageDeliveryModeStrategy;
            this.rpc                     = rpc;
            this.sendReceive             = sendReceive;
            this.connectionConfiguration = connectionConfiguration;
        }