static void Main()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.NHibernateCustomSagaFinder");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();

        #region NHibernateSetup

        busConfiguration.UsePersistence <NHibernatePersistence>()
        .ConnectionString(@"Data Source=.\SqlExpress;Initial Catalog=NHCustomSagaFinder;Integrated Security=True");

        #endregion

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new StartOrder
            {
                OrderId = "123"
            });

            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
    static void Main()
    {
        LogManager.Use <DefaultFactory>()
        .Level(LogLevel.Warn);

        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.ErrorHandling.WithSLR");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            Console.WriteLine("Press any key to send a message that will throw an exception.");
            Console.WriteLine("To exit, press Ctrl + C");

            while (true)
            {
                Console.ReadLine();
                MyMessage m = new MyMessage
                {
                    Id = Guid.NewGuid()
                };
                bus.SendLocal(m);
            }
        }
    }
Exemple #3
0
    static void Main()
    {
        #region ConfigureLogging

        Common.Logging.LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter
        {
            Level = LogLevel.Info
        };

        NServiceBus.Logging.LogManager.Use <CommonLoggingFactory>();

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Logging.CommonLogging");

        #endregion

        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #4
0
        static async Task RunLoop(IStartableBus endpointInstance)
        {
            while (true)
            {
                log.Info("Press 'P' to place an order, or 'Q' to quit.");
                var key = Console.ReadKey();
                Console.WriteLine();

                switch (key.Key)
                {
                case ConsoleKey.P:
                    // Instantiate the command
                    var command = new PlaceOrder
                    {
                        OrderId   = Guid.NewGuid().ToString(),
                        OrderText = "First line\r\nSecond line"
                    };

                    // Send the command to the local endpoint
                    log.Info($"Sending PlaceOrder command, OrderId = {command.OrderId}");
                    endpointInstance.SendLocal(command);

                    break;

                case ConsoleKey.Q:
                    return;

                default:
                    log.Info("Unknown input. Please try again.");
                    break;
                }
            }
        }
    static void Main()
    {
        #region ConfigureAppender
        MyConsoleAppender consoleAppender = new MyConsoleAppender
        {
            Color = ConsoleColor.Green
        };
        BasicConfigurator.Configure(consoleAppender);
        LogManager.Use <Log4NetFactory>();
        #endregion

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Log4Net.Appender");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
 public static void SendMessages(IStartableBus bus)
 {
     var startNew = Stopwatch.StartNew();
     while (startNew.ElapsedMilliseconds < 10000)
     {
         bus.SendLocal(PersonCreater.Create());
     }
     Console.WriteLine(PersonHandler.count);
 }
Exemple #7
0
    static void Main()
    {
        #region ConfigureLog4Net
        PatternLayout layout = new PatternLayout
        {
            ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"
        };
        layout.ActivateOptions();
        ColoredConsoleAppender consoleAppender = new ColoredConsoleAppender
        {
            Threshold = Level.Info,
            Layout    = layout
        };
        consoleAppender.ActivateOptions();
        RollingFileAppender fileAppender = new RollingFileAppender
        {
            DatePattern        = "yyyy-MM-dd'.txt'",
            RollingStyle       = RollingFileAppender.RollingMode.Composite,
            MaxFileSize        = 10 * 1024 * 1024,
            MaxSizeRollBackups = 10,
            LockingModel       = new FileAppender.MinimalLock(),
            StaticLogFileName  = false,
            File         = @"nsblog",
            Layout       = layout,
            AppendToFile = true,
            Threshold    = Level.Debug,
        };
        fileAppender.ActivateOptions();

        BasicConfigurator.Configure(fileAppender, consoleAppender);
        #endregion
        #region UseConfig

        LogManager.Use <Log4NetFactory>();

        // Then continue with your BusConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Logging.Log4NetCustom");

        #endregion

        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #8
0
    static void Main()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.UoWWithChildContainers");

        #region ContainerConfiguration
        Container container = new Container(x =>
        {
            x.For <IDocumentStore>().Use(new DocumentStore
            {
                Url             = "http://localhost:32076",
                DefaultDatabase = "Samples.UoWWithChildContainers"
            }
                                         .Initialize());
            x.For <IDocumentSession>().Use(c => c.GetInstance <IDocumentStore>().OpenSession());
        });

        busConfiguration.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(container));
        #endregion

        #region PipelineRegistration
        busConfiguration.Pipeline.Register <RavenUnitOfWork.Registration>();
        #endregion

        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        int orderNumber = 1;

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();

            Console.Out.WriteLine("Press any key to send a message. Press `q` to quit");

            Console.Out.WriteLine("After storing a few orders you can open a browser and view them at http://localhost:32076/studio/index.html#databases/documents?collection=Orders&database=Samples.UoWWithChildContainers");

            while (Console.ReadKey().ToString() != "q")
            {
                bus.SendLocal(new PlaceOrder
                {
                    OrderNumber = string.Format("Order-{0}", orderNumber),
                    OrderValue  = 100
                });

                orderNumber++;
            }
        }
    }
Exemple #9
0
    static void Main()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.ComplexSagaFindingLogic");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new StartOrder
            {
                OrderId = "123"
            });
            bus.SendLocal(new StartOrder
            {
                OrderId = "456"
            });
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #10
0
    static void Main()
    {
        #region ConfigureLogging
        BusConfiguration busConfig = new BusConfiguration();
        busConfig.EndpointName("Samples.Logging.Default");
        //Note that no config is required in V5 since logging is enabled by default
        #endregion
        busConfig.UseSerialization <JsonSerializer>();
        busConfig.EnableInstallers();
        busConfig.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfig))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #11
0
    static void Main()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.FaultTolerance.Server");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence <InMemoryPersistence>();

        // To disable second level retries(SLR), uncomment the following line. SLR is enabled by default.
        // busConfiguration.DisableFeature<SecondLevelRetries>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #12
0
    static void Main()
    {
        #region ContainerConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.StructureMap");

        Container container = new Container(x => x.For <MyService>().Use(new MyService()));
        busConfiguration.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(container));
        #endregion
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
Exemple #13
0
    static void Main()
    {
        #region self-hosting

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.SelfHosting");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();

            Console.WriteLine("\r\nBus created and configured; press any key to stop program\r\n");
            bus.SendLocal(new MyMessage());
            Console.ReadKey();
        }

        #endregion
    }
Exemple #14
0
    static void Main()
    {
        #region ContainerConfiguration
        BusConfiguration configuration = new BusConfiguration();
        configuration.EndpointName("Samples.Unity");

        UnityContainer container = new UnityContainer();
        container.RegisterInstance(new MyService());
        configuration.UseContainer <UnityBuilder>(c => c.UseExistingContainer(container));
        #endregion
        configuration.UseSerialization <JsonSerializer>();
        configuration.UsePersistence <InMemoryPersistence>();
        configuration.EnableInstallers();

        using (IStartableBus bus = Bus.Create(configuration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
Exemple #15
0
    static void Main()
    {
        #region ContainerConfiguration
        BusConfiguration configuration = new BusConfiguration();
        configuration.EndpointName("Samples.Ninject");

        StandardKernel kernel = new StandardKernel();
        kernel.Bind <MyService>().ToConstant(new MyService());
        configuration.UseContainer <NinjectBuilder>(c => c.ExistingKernel(kernel));
        #endregion
        configuration.UseSerialization <JsonSerializer>();
        configuration.UsePersistence <InMemoryPersistence>();
        configuration.EnableInstallers();

        using (IStartableBus bus = Bus.Create(configuration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
    static void Main()
    {
        #region ContainerConfiguration
        BusConfiguration configuration = new BusConfiguration();
        configuration.EndpointName("Samples.Spring");

        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
        configuration.UseContainer <SpringBuilder>(c => c.ExistingApplicationContext(applicationContext));
        #endregion
        configuration.UseSerialization <JsonSerializer>();
        configuration.UsePersistence <InMemoryPersistence>();
        configuration.EnableInstallers();

        using (IStartableBus bus = Bus.Create(configuration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
Exemple #17
0
    static void Main()
    {
        #region ContainerConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Autofac");

        ContainerBuilder builder = new ContainerBuilder();
        builder.RegisterInstance(new MyService());
        IContainer container = builder.Build();
        busConfiguration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));
        #endregion
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
    static void Main()
    {
        #region ConfigureRabbit

        BusConfiguration busConfig = new BusConfiguration();
        busConfig.EndpointName("Samples.RabbitMQ.Simple");
        busConfig.UseTransport <RabbitMQTransport>()
        .ConnectionString("host=localhost");

        #endregion

        busConfig.UseSerialization <JsonSerializer>();
        busConfig.EnableInstallers();
        busConfig.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfig))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #19
0
    static void Main()
    {
        #region ConfigureNLog

        LoggingConfiguration config = new LoggingConfiguration();

        ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget
        {
            Layout = "${level}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}"
        };
        config.AddTarget("console", consoleTarget);
        config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget));

        LogManager.Configuration = config;
        #endregion
        #region UseConfig

        NServiceBus.Logging.LogManager.Use <NLogFactory>();

        // Then continue with your BusConfiguration
        BusConfiguration busConfig = new BusConfiguration();
        busConfig.EndpointName("Samples.Logging.NLogCustom");

        #endregion

        busConfig.UseSerialization <JsonSerializer>();
        busConfig.EnableInstallers();
        busConfig.UsePersistence <InMemoryPersistence>();

        using (IStartableBus bus = Bus.Create(busConfig))
        {
            bus.Start();
            bus.SendLocal(new MyMessage());
            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }
Exemple #20
0
    static void Main()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.RavenDBCustomSagaFinder");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.EnableInstallers();

        #region RavenDBSetup

        IDocumentStore defaultStore = new DocumentStore()
        {
            Url             = "http://localhost:32076",
            DefaultDatabase = "Samples.RavenDBCustomSagaFinder"
        }
        .RegisterListener(new UniqueConstraintsStoreListener())
        .Initialize();

        busConfiguration.UsePersistence <RavenDBPersistence>()
        .DoNotSetupDatabasePermissions()     //Only required to simplify the sample setup
        .SetDefaultDocumentStore(defaultStore);

        #endregion

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.SendLocal(new StartOrder
            {
                OrderId = "123"
            });

            Console.WriteLine("\r\nPress any key to stop program\r\n");
            Console.ReadKey();
        }
    }