static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Configure the host to use SQL to store events and snapshots. You don't have to use // the configuration action - both providers will default to a connection string // named "SeekU." This simply shows how you can configure each provider at runtime. host // Sample of using configuration actions to set connectionstrings .ForEventStore().Use<SqlEventStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }) // This could be a different connection if necessary .ForSnapshotStore().Use<SqlSnapshotStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }); // Using the default conenction string would look like this (less verbose): //config.ForEventStore().Use<SqlEventStore>().ForSnapshotStore().Use<SqlSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Configure file-based event storeage host.ForEventStore().Use <JsonFileEventStore>() // Example of using an optional configuration action. In this cas it sets the snapshot store's file name .ForSnapshotStore().Use <JsonFileSnapshotStore>(store => { store.FileName = "snapshot-instance.json"; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Configure file-based event storeage host.ForEventStore().Use<JsonFileEventStore>() // Example of using an optional configuration action. In this cas it sets the snapshot store's file name .ForSnapshotStore().Use<JsonFileSnapshotStore>(store => { store.FileName = "snapshot-instance.json"; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); host.ForEventStore().Use <MongoEventStore>() .ForSnapshotStore().Use <MongoSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Configure the host to use SQL to store events and snapshots. You don't have to use // the configuration action - both providers will default to a connection string // named "SeekU." This simply shows how you can configure each provider at runtime. host // Sample of using configuration actions to set connectionstrings .ForEventStore().Use <SqlEventStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }) // This could be a different connection if necessary .ForSnapshotStore().Use <SqlSnapshotStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }); // Using the default conenction string would look like this (less verbose): //config.ForEventStore().Use<SqlEventStore>().ForSnapshotStore().Use<SqlSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
private void SendSeekU() { // Use a custom configuration with our own ICommandBus implementation var host = new SeekUHostConfiguration <NsbStructureMapResolver>(); // Configure commands to be published via NServiceBus instead of the // in-memory bus. host.ForCommandBus().Use <NServiceCommandBus>(); // The NServiceCommandBus requires IBus as a constructor parameter. // This tells the resolver what to use for that dependency. host.For <IBus>().Use(Bus); var seekUBus = host.GetCommandBus(); var id = Guid.NewGuid(); Console.WriteLine("Sending create account command"); seekUBus.Send(new CreateNewAccountCommand(id, 950)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 50)); Console.WriteLine("Sending credit account command"); seekUBus.Send(new CreditAccountCommand(id, 120)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 350)); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var config = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Normally you'd configure providers here. This "in memory" sample // uses the default providers, so no configuration is necessary. var bus = config.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account var newAccountCommand = new CreateNewAccountCommand(id, 950); // Simple validation example. var validation = bus.Validate(newAccountCommand); Console.WriteLine("CreateNewAccountCommand is valid? {0}", validation.Success); bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var config = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Normally you'd configure providers here. This "in memory" sample // uses the default providers, so no configuration is necessary. var bus = config.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account var newAccountCommand = new CreateNewAccountCommand(id, 950); // Simple validation example. var validation = bus.Validate(newAccountCommand); Console.WriteLine("CreateNewAccountCommand is valid? {0}", validation.Success); bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Update with your connection string const string connectionString = "DefaultEndpointsProtocol=https;AccountName=[Your account name];AccountKey[Your account key]"; host .ForEventStore().Use<AzureTableEventStore>(store => { store.TableConnectionString = connectionString; }) .ForSnapshotStore().Use<AzureBlobSnapshotStore>(store => { store.BlobConnectionString = connectionString; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 95)); Console.WriteLine("Azure event created"); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 5)); Console.WriteLine("Azure event created"); bus.Send(new CreditAccountCommand(id, 12)); Console.WriteLine("Azure event created"); Console.WriteLine("Azure snapshot created"); bus.Send(new DebitAccountCommand(id, 35)); Console.WriteLine("Azure event created"); Console.Read(); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Update with your connection string const string connectionString = "DefaultEndpointsProtocol=https;AccountName=[Your account name];AccountKey[Your account key]"; host .ForEventStore().Use <AzureTableEventStore>(store => { store.TableConnectionString = connectionString; }) .ForSnapshotStore().Use <AzureBlobSnapshotStore>(store => { store.BlobConnectionString = connectionString; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 95)); Console.WriteLine("Azure event created"); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 5)); Console.WriteLine("Azure event created"); bus.Send(new CreditAccountCommand(id, 12)); Console.WriteLine("Azure event created"); Console.WriteLine("Azure snapshot created"); bus.Send(new DebitAccountCommand(id, 35)); Console.WriteLine("Azure event created"); Console.Read(); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); host.ForEventStore().Use<MongoEventStore>() .ForSnapshotStore().Use<MongoSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
public override void Run() { Trace.WriteLine("Starting processing of messages"); _client.OnMessage(message => { try { Trace.WriteLine("Processing Service Bus message: " + message.SequenceNumber.ToString()); _host.GetCommandBus().Send(GetCommandBody(message)); // To handle events, use the following: //_host.GetEventBus().PublishEvents(GetEventBody(message)); message.Complete(); } catch { // Handle any message processing specific exceptions here } }); _completedEvent.WaitOne(); }
public void Handle(CreateNewAccountCommand message) { Console.WriteLine("Create account message received"); Host.GetCommandBus().Send(message); }
private void SendSeekU() { // Use a custom configuration with our own ICommandBus implementation var host = new SeekUHostConfiguration<NsbStructureMapResolver>(); // Configure commands to be published via NServiceBus instead of the // in-memory bus. host.ForCommandBus().Use<NServiceCommandBus>(); // The NServiceCommandBus requires IBus as a constructor parameter. // This tells the resolver what to use for that dependency. host.For<IBus>().Use(Bus); var seekUBus = host.GetCommandBus(); var id = Guid.NewGuid(); Console.WriteLine("Sending create account command"); seekUBus.Send(new CreateNewAccountCommand(id, 950)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 50)); Console.WriteLine("Sending credit account command"); seekUBus.Send(new CreditAccountCommand(id, 120)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 350)); }