Exemple #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            Bus = BusInitializer.CreateBus("CustomerPortal_WebApp", x => { });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            /**
             * Add mass transit to inject the mass transit classes we are going to use to handle
             * the messaging with the rabbiymq
             * Install-Package MassTransit.Extensions.DependencyInjection -Version 6.1.0
             * Install-Package MassTransit.RabbitMQ -Version 6.1.0
             *
             **/
            services.AddHealthChecks();
            services.AddMassTransit();

            //Whenever reference  IBusControl an instance will be injected
            // when you specify the queue name , when the message arrive to the exchange the binding will know to which queue it will be sent
            //rabbitmq://a-machine-name/a-virtual-host
            services.AddSingleton(provider => BusInitializer.CreateBus("rabbitmq://localhost", "", "MassTransitPubSubExample_queue_1", cfg => { /**nothing to be added to the configuration in here**/ }));

            //IBusControl :  IBus, IPublishEndpoint, IPublishObserverConnector, IPublishEndpointProvider, ISendEndpointProvider, ISendObserverConnector, IConsumePipeConnector, IRequestPipeConnector, IConsumeMessageObserverConnector, IConsumeObserverConnector, IReceiveObserverConnector, IReceiveEndpointObserverConnector, IReceiveConnector, IEndpointConfigurationObserverConnector, IProbeSite
            //IBus        :  is a logical endpoint contains (1 local endpoint - 0+ recieve endpoints)
            //IPublishEndpoint : let's the underlying transport know exactly which is the actual endpoint the message will be send to , (RabbitMQ , Azure Service Bus)
            //Whenever reference  IBus,IPublishEndpoint the same instance of IBusControl will be injected
            services.AddSingleton <IBus>(provider => provider.GetRequiredService <IBusControl>());
            services.AddSingleton <IPublishEndpoint>(provider => provider.GetRequiredService <IBusControl>());

            //BusService : if bus control will be managed by the us then we will use BusService to Start/Stop the bus
            //when un comment the app will keep loading without result
            //services.AddSingleton<IHostedService, BusService>();

            //whenever ref. the class inject an instance
            services.AddSingleton <MessageProducer, MessageProducer>();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            // register each consumer manually
            builder.RegisterType <PickConsumer>().AsSelf();

            //or use Autofac's scanning capabilities -- SomeClass is any class in the correct assembly
            //builder.RegisterAssemblyTypes(typeof(PickConsumer).Assembly)
            //    .Where(t => t.Implements<IConsumer>())
            //    .AsSelf();

            //now we add the bus
            builder.Register(c => ServiceBusFactory.New(sbc =>
            {
                sbc.UseRabbitMq();
                sbc.ReceiveFrom(BusInitializer.GetUri("PickService"));

                //this will find all of the consumers in the container and
                //register them with the bus.
                sbc.Subscribe(x => x.LoadFrom(c.Resolve <ILifetimeScope>()));
            })).As <IServiceBus>().SingleInstance().AutoActivate();

            builder.Build();

            Console.WriteLine("Waiting..");
            Console.ReadKey();
        }
        public BusInitializerTests()
        {
            configurationSection = new EasyNetQConfigurationSection();
            bus = Substitute.For <IBus>();
            subscriptionHandler = Substitute.For <IEasyNetQSubscriptionHandler>();

            sut = new BusInitializer(bus, subscriptionHandler, configurationSection);
        }
Exemple #5
0
 public static void Listen()
 {
     var bus = BusInitializer.CreateBus("Subscriber", x =>
     {
         x.Subscribe(subs =>
         {
             subs.Consumer <AdPriceChanged>().Permanent();
         });
     });
 }
Exemple #6
0
 private static void Main(string[] args)
 {
     using (
         BusInitializer.CreateBus("OrderSaga",
                                  x => x.Subscribe(c => c.Saga(new InMemorySagaRepository <OrderSaga>()).Permanent())))
     {
         Console.WriteLine("Waiting..");
         Console.ReadKey();
     }
 }
 public void Start()
 {
     _bus = BusInitializer.CreateBus("CustomerPortal_Backend", x =>
     {
         x.Subscribe(subs =>
         {
             subs.Consumer <TicketOpenedConsumer>().Permanent();
         });
     });
 }
Exemple #8
0
    static void Main(string[] args)
    {
      var bus = BusInitializer.CreateBus("TestSubscriber", x =>
      {
        x.Subscribe(subs =>
        {
          subs.Consumer<SomethingHappenedConsumer>().Permanent();
        });
      });

      Console.ReadKey();

      bus.Dispose();
    }
Exemple #9
0
        private static void Main(string[] args)
        {
            using (var bus = BusInitializer.CreateBus("OrderSender", x => { }))
            {
                var text = "";

                while (text != "quit")
                {
                    Console.Write("Enter an order: ");
                    text = Console.ReadLine();

                    var message = new Order {
                        What = text, When = DateTime.Now, CorrelationId = Guid.NewGuid()
                    };
                    var receiverUri = BusInitializer.GetUri("OrderSaga");

                    bus.GetEndpoint(receiverUri)
                    .Send(message);
                }
            }
        }
Exemple #10
0
        public static void RegisterServices(ContainerBuilder builder)
        {
            builder.RegisterType <UserSystemContext>().InstancePerRequest();
            //使用构造函数配置
            builder.Register(c => new CustomUserStore(c.Resolve <UserSystemContext>())).As <IUserStore <User> >().InstancePerRequest();
            //使用构造函数配置
            //  builder.Register(c => new CustomUserManager(c.Resolve<CustomUserStore>())).InstancePerLifetimeScope();

            builder.RegisterType <CustomUserManager>().UsingConstructor(typeof(IUserStore <User>)).InstancePerRequest();

            builder.RegisterType <UnitOfWork>().As <IUnitOfWork>().InstancePerRequest();

            builder.RegisterType <UserAppService>().As <IUserAppService>().InstancePerRequest();

            builder.RegisterType <UserRepository>().As <IUserRepository>().InstancePerRequest();

            builder.Register <IBusControl>(c => BusInitializer.CreateBus())
            .As <IBusControl>()
            .As <IPublishEndpoint>()
            .SingleInstance();
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ApproveConsumer>().AsSelf();

            builder.Register(c => ServiceBusFactory.New(sbc =>
            {
                sbc.UseRabbitMq();
                sbc.ReceiveFrom(BusInitializer.GetUri("OrderApprover"));

                sbc.SetConcurrentConsumerLimit(5);
                sbc.SetDefaultRetryLimit(5);

                //this will find all of the consumers in the container and
                //register them with the bus.
                sbc.Subscribe(x => x.LoadFrom(c.Resolve <ILifetimeScope>()));
            })).As <IServiceBus>().SingleInstance().AutoActivate();

            builder.Build();

            Console.WriteLine("Waiting..");
            Console.ReadKey();
        }
Exemple #12
0
        static void Main(string[] args)
        {
            //BusInitializer.Main();


            IBus bus = new BusInitializer().CreateBus();

            //IBus bus = BusInitializer.CreateBus("newQueue");

            while (true)
            {
                Console.WriteLine("Do you want to insert an (1)Individual or (2)Company? Or type Quit");
                var input = Console.ReadLine();
                if (input == "Quit")
                {
                    break;
                }
                else if (input == "1")
                {
                    DTO.Customers.Individual individual = new DTO.Customers.Individual();
                    Console.WriteLine("Please Enter a First Name or type Quit:");
                    input = Console.ReadLine();
                    if (input == "Quit")
                    {
                        break;
                    }
                    individual.FirstName = input;
                    Console.WriteLine("Please Enter a Last Name or type Quit:");
                    input = Console.ReadLine();
                    if (input == "Quit")
                    {
                        break;
                    }
                    individual.LastName = input;
                    Console.WriteLine("Please Enter the contact number or type Quit:");
                    input = Console.ReadLine();
                    if (input == "Quit")
                    {
                        break;
                    }
                    individual.ContactNumber = input;

                    bus.Publish(individual);
                }
                else if (input == "2")
                {
                    DTO.Customers.Company company = new DTO.Customers.Company();
                    Console.WriteLine("Please Enter a Company Name or type Quit:");
                    input = Console.ReadLine();
                    if (input == "Quit")
                    {
                        break;
                    }
                    company.Name = input;
                    Console.WriteLine("Please Enter a Company Contact Number or type Quit:");
                    input = Console.ReadLine();
                    if (input == "Quit")
                    {
                        break;
                    }
                    company.ContactNumber = input;
                    bus.Publish(company);
                }
            }


            //bus.Publish()
            Console.ReadLine();



            //DTO.Customers.IIndividual individual = new Individual();
            //  individual.ContactNumber = "1234";
            //  individual.FirstName = "FirstName";
            //  individual.LastName = "Lastname";

            //  BusinessLayer.Customers.Customers customerLayer = new BusinessLayer.Customers.Customers();
            //  customerLayer.InsertIndividual(individual);
            //  //Repo.Customers.Command.InsertCustomer(newIndividual);

            //var df = Repo.Customers.ReadOnly.GetCustomerById(1);
            //Console.WriteLine(df.ContactNumber.ToString() + " - ");
        }