private void ConnectObservers()
 {
     _publishObserver = new LoggingPublishObserver(LogObserver);
     _sendObserver    = new LoggingSendObserver(LogObserver);
     _azureBus.ConnectPublishObserver(_publishObserver);
     _azureBus.ConnectSendObserver(_sendObserver);
 }
Beispiel #2
0
        public virtual async Task Start()
        {
            _sent      = new TestSendObserver(TestTimeout);
            _consumed  = new BusTestConsumeObserver(TestTimeout);
            _published = new BusTestPublishObserver(TestTimeout);

            PreCreateBus?.Invoke(this);

            _bus = CreateBus();

            ConnectObservers(_bus);

            _busHandle = await _bus.StartAsync().ConfigureAwait(false);

            BusSendEndpoint = await GetSendEndpoint(_bus.Address).ConfigureAwait(false);

            InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false);

            _inputQueueSendObserver = InputQueueSendEndpoint.ConnectSendObserver(_sent);

            _busConsumeObserver = _bus.ConnectConsumeObserver(_consumed);

            _busPublishObserver = _bus.ConnectPublishObserver(_published);

            _busSendObserver = _bus.ConnectSendObserver(_sent);
        }
Beispiel #3
0
        /// <summary>
        ///     Connects the given ticket to all requests sent through the bus.
        /// </summary>
        /// <param name="busControl">The bus control.</param>
        /// <param name="ticket">The ticket.</param>
        public static void ConnectTicket(this IBusControl busControl, string ticket)
        {
            var propagator = new EncryptedTicketPropagator(ticket);

            busControl.ConnectSendObserver(propagator);
            busControl.ConnectPublishObserver(propagator);
        }
Beispiel #4
0
        /// <summary>
        ///     Connects the thread principal to all requests sent through the bus.
        /// </summary>
        /// <param name="busControl">The bus control.</param>
        public static void ConnectThreadPrincipal(this IBusControl busControl)
        {
            var propagator = new PrincipalTicketPropagator();

            busControl.ConnectSendObserver(propagator);
            busControl.ConnectPublishObserver(propagator);
        }
Beispiel #5
0
        public bool Start(HostControl hostControl)
        {
            _bus.ConnectConsumeObserver(new ConsumeObserver());

            _bus.ConnectSendObserver(new SendObserver());

            _bus.Start();

            _bus.Publish(new TestCommand {
                JobId = 1
            });

            return(true);
        }
Beispiel #6
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Bus host is being started...");

            await _busControl.StartAsync(cancellationToken);

            if (_config.EnableMessagesAudit)
            {
                _busControl.ConnectConsumeObserver(_consumingAuditObserver);
                _busControl.ConnectPublishObserver(_publishingAuditObserver);
                _busControl.ConnectSendObserver(_sendingAuditObserver);
            }

            _logger.LogInformation("Bus host has been started");
        }
        private static void RunTransitPublisher()
        {
            // Create service bus controller
            IBusControl control = Bus.Factory.CreateUsingRabbitMq(
                rbt =>
            {
                rbt.Host(
                    ConnectionProperties.HostUri,
                    settings =>
                {
                    settings.Username("henry");
                    settings.Password("henry");
                }
                    );
            }
                );

            // Register Send Observer
            control.ConnectSendObserver(new SendObjectObserver());

            // Create a task that allows us to send the command to a specified queue.
            Task <ISendEndpoint> sendEndpointTask = control.GetSendEndpoint(new Uri($"{ConnectionProperties.HostAddress}/{ConnectionProperties.EndPoint}"));
            ISendEndpoint        sendEndPoint     = sendEndpointTask.Result;

            // Send command
            Task sendTask = sendEndPoint.Send <IRegisterCustomer>(
                new
            {
                Address         = "New Street",
                Id              = Guid.NewGuid(),
                Preferred       = true,
                RegisteredDate  = DateTime.UtcNow,
                Name            = "A Company Ltd.",
                Type            = 1,
                DefaultDiscount = 0,
                Target          = "Customers",
                Importance      = 1
            }
                );

            Console.ReadKey();
        }
Beispiel #8
0
 /// <summary>
 ///     Observing sent messages
 /// </summary>
 /// <param name="sendObserver"></param>
 public void AddLog(ISendObserver sendObserver)
 {
     _busControl.ConnectSendObserver(sendObserver);
 }
        // Override and inject if you need a more custom startup configuration
        public virtual Task StartAsync(Type[] listenerNoQueueTypes = null)
        {
            if (_options.UseInMemoryBus)
            {
                throw new NotSupportedException("InMemory bus is not currently supported");
                // _busControl = Bus.Factory.CreateUsingInMemory(sbc =>
                // {
                //     if (_options.BusObserver != null)
                //     {
                //         sbc.AddBusFactorySpecification(_options.BusObserver);
                //     }

                //     sbc.UseRetry(Retry.Immediate(5));

                //     foreach (var handler in handlers)
                //     {
                //         sbc.ReceiveEndpoint(handler.MessageType.Name, c =>
                //         {
                //             c.LoadFrom(_services);
                //         });
                //     }
                // });
            }
            else
            {
                _busControl = Bus.Factory.CreateUsingRabbitMq(sbc =>
                {
                    var host = sbc.Host(new Uri(_options.RabbitMQUri), h =>
                    {
                        h.Username(_options.RabbitMQUsername);
                        h.Password(_options.RabbitMQPassword);
                    });

                    if (_options.BusObserver != null)
                    {
                        sbc.AddBusFactorySpecification(_options.BusObserver);
                    }

                    if (_options.RetryPolicy != null)
                    {
                        sbc.UseRetry(_options.RetryPolicy);
                    }

                    var allHandlers = _manager.GetAllHandlers().ToList();

                    foreach (var msgTypes in allHandlers
                             .Where(h => h.GenericType == typeof(IDistributedEventListener <>))
                             .GroupBy(h => h.ImplementationType))
                    {
                        sbc.ReceiveEndpoint(host, c =>
                        {
                            foreach (var handler in msgTypes)
                            {
                                ConsumerConfiguratorCache.Configure(handler, c, _services);
                            }
                        });
                    }

                    foreach (var msgTypes in allHandlers
                             .Where(h => h.GenericType == typeof(IEventListener <>) || h.GenericType == typeof(IFaultHandler <>))
                             .GroupBy(h => h.ImplementationType))
                    {
                        sbc.ReceiveEndpoint(host, msgTypes.Key.Name, c =>
                        {
                            foreach (var handler in msgTypes)
                            {
                                ConsumerConfiguratorCache.Configure(handler, c, _services);
                            }
                        });
                    }

                    foreach (var msgTypes in allHandlers
                             .Where(h => h.GenericType == typeof(ICommandHandler <,>) || h.GenericType == typeof(ICommandHandler <>))
                             .GroupBy(h => h.MessageType))
                    {
                        sbc.ReceiveEndpoint(host, msgTypes.Key.Name, c =>
                        {
                            foreach (var handler in msgTypes)
                            {
                                ConsumerConfiguratorCache.Configure(handler, c, _services);
                            }
                        });
                    }
                });
            }

            if (_options.ReceiveObserver != null)
            {
                _busControl.ConnectReceiveObserver(_options.ReceiveObserver);
            }

            if (_options.SendObserver != null)
            {
                _busControl.ConnectSendObserver(_options.SendObserver);
            }

            if (_options.ConsumeObserver != null)
            {
                _busControl.ConnectConsumeObserver(_options.ConsumeObserver);
            }

            if (_options.PublishObserver != null)
            {
                _busControl.ConnectPublishObserver(_options.PublishObserver);
            }

            return(_busControl.StartAsync());
        }
 public ConnectHandle ConnectSendObserver(ISendObserver observer)
 {
     return(_busControl.ConnectSendObserver(observer));
 }