public CountedMessageSubscriber(IGeneralBus bus) : base(bus) { EventOrder = new List <int>(); MsgOrder = new List <int>(); Subscribe <CountedTestMessage>(this); Subscribe <CountedEvent>(this); }
protected QueuedSubscriber(IGeneralBus bus, bool idempotent = true) { if (bus == null) { throw new ArgumentNullException(nameof(bus)); } _generalBus = bus; _internalBus = new CommandBus("SubscriptionBus"); if (idempotent) { _messageQueue = new QueuedHandler( new IdempotentHandler <Message>( new AdHocHandler <Message>(_internalBus.Publish) ), "SubscriptionQueue"); } else { _messageQueue = new QueuedHandler( new AdHocHandler <Message>(_internalBus.Publish), "SubscriptionQueue"); } _messageQueue.Start(); }
public TestCommandSubscriber(IGeneralBus bus) { _bus = bus; TestCommand2Handled = 0; _bus.Subscribe <TestCommands.TestCommand2> (this); _bus.Subscribe <TestCommands.TestCommand3>(this); }
private static ReactiveCommand FireCommandEx( IGeneralBus bus, Func <Object, Command> commandFunc, IObservable <bool> canExecute = null, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { if (scheduler == null) { scheduler = RxApp.MainThreadScheduler; } Func <object, Task> task = async _ => await Task.Run(() => { var c = commandFunc(_); if (c != null) { bus.Fire(c, userErrorMsg, responseTimeout, ackTimeout); } }); var cmd = ReactiveCommand.CreateFromTask(task, canExecute, scheduler); cmd.ThrownExceptions .SelectMany(ex => UserError.Throw(userErrorMsg ?? ex.Message, ex)) .ObserveOn(MainThreadScheduler).Subscribe(result => { //This will return the recovery option returned from the registered user error handler //right now this is a simple message box in the view code behind /* n.b. this forces evaluation/execution of the select many */ }); return(cmd); }
public BusConnector(IGeneralBus left, IGeneralBus right) { _left = new BusAdapter(left); _right = new BusAdapter(right); _left.Subscribe(_right); _right.Subscribe(_left); }
public TcpBusServerSide( IPAddress hostIp, int commandPort, IGeneralBus messageBus) : base(hostIp, commandPort, messageBus) { _commandPortListener = ConfigureTcpListener(CommandEndpoint, TcpMessageArrived); }
protected TransientSubscriber(IGeneralBus bus) : this((IBus)bus) { if (bus == null) { throw new ArgumentNullException(nameof(bus)); } _commandSubscriber = bus; }
public TcpOutboundMessageHandler( IGeneralBus messageBus, QueuedHandler outboundMessageQueuedHandler) { _messageBus = messageBus; _outboundMessageQueuedHandler = outboundMessageQueuedHandler; _messageBus.Subscribe(this); }
public TcpBusClientSide( IGeneralBus messageBus, IPAddress hostIP, int commandPort, ITcpConnection tcpConnection = null) : base(hostIP, commandPort, messageBus) { _tcpConnection = tcpConnection ?? CreateTcpConnection(CommandEndpoint); }
public TestInheritedMessageSubscriber(IGeneralBus bus, bool idempotent = true) : base(bus, idempotent) { Reset(); Subscribe <TestDomainEvent>(this); Subscribe <ParentTestDomainEvent>(this); Subscribe <ChildTestDomainEvent>(this); Subscribe <GrandChildTestDomainEvent>(this); }
public AccountSvc(IGeneralBus bus, IRepository repo) : base(bus) { _repo = repo; bus.Subscribe <CreateAccount>(this); bus.Subscribe <ApplyCredit>(this); bus.Subscribe <ApplyDebit>(this); }
//public IEventStoreConnection EsConnection { get; private set; } //public void Bootstrap() //{ // _es = new EventStoreLoader(); // _es.SetupEventStore(new DirectoryInfo(@"C:\Users\rosed18169\source\EventStore-OSS-Win-v3.9.4")); // EsConnection = _es.Connection; // _esRepository = new GetEventStoreRepository(_es.Connection); // Locator.CurrentMutable.RegisterConstant(_esRepository, typeof(IRepository)); // _bus = new CommandBus("testBus", false); //} public void Run() { Console.WriteLine("Hit return on an empty line to cancel..."); Console.WriteLine("Enter a value. Negative values are debits, positive are credits."); var accountId = Guid.NewGuid(); _bus = new CommandBus("testBus", false); Bootstrap.Configure(_bus); //var svc = new AccountSvc(_bus, _esRepository); _bus.Fire(new CreateAccount( accountId, "TheAccount", Guid.NewGuid(), Guid.Empty)); _accountReadModel = new AccountRM(accountId); while (true) { var line = Console.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { break; } try { var input = new UserInput(line); if (input.Type == UserInput.InputType.Debit) { _bus.Fire(new ApplyDebit( accountId, input.Amount, Guid.NewGuid(), Guid.Empty)); } else { _bus.Fire(new ApplyCredit( accountId, input.Amount, Guid.NewGuid(), Guid.Empty), responseTimeout: TimeSpan.FromSeconds(60)); } } catch (CommandException e) { var msg = e.InnerException == null ? e.Message : e.InnerException.Message; Console.WriteLine(msg); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } }
public static void Configure(IGeneralBus bus) { _es = new EventStoreLoader(); _es.SetupEventStore(new DirectoryInfo(@"C:\Users\rosed18169\source\EventStore-OSS-Win-v3.9.4")); _esConnection = _es.Connection; _esRepository = new GetEventStoreRepository(_es.Connection); Locator.CurrentMutable.RegisterConstant(_esRepository, typeof(IRepository)); _acctSvc = new AccountSvc(bus, _esRepository); }
public NullableBus(IGeneralBus target, bool directToNull = true, string name = null) { if (target == null) { throw new ArgumentNullException(nameof(target)); } _target = target; Name = name ?? _target.Name; RedirectToNull = directToNull; }
public static ReactiveCommand <Unit> BuildFireCommand( this IGeneralBus bus, Func <Command> commandFunc, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { return(FireCommands(bus, new[] { commandFunc }, null, scheduler, userErrorMsg, responseTimeout, ackTimeout)); }
/// <summary> /// BuildFireCommandEx() does the same thing as BuildFireCommand(), except commandFunc must be defined /// as a function that takes Object as input and returns Command as result. /// </summary> /// <param name="bus"></param> /// <param name="commandFunc"></param> /// <param name="scheduler"></param> /// <param name="userErrorMsg"></param> /// <param name="responseTimeout"></param> /// <param name="ackTimeout"></param> /// <returns></returns> public static ReactiveCommand BuildFireCommandEx( this IGeneralBus bus, Func <Object, Command> commandFunc, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { return(FireCommandEx(bus, commandFunc, null, scheduler, userErrorMsg, responseTimeout, ackTimeout)); }
public static ReactiveCommand BuildFireCommand( this IGeneralBus bus, IEnumerable <Func <Command> > commands, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { return(FireCommands(bus, commands, null, scheduler, userErrorMsg, responseTimeout, ackTimeout)); }
public TestQueuedSubscriber(IGeneralBus bus) : base(bus) { TimesTestMessageHandled = 0; TimesTestMessage2Handled = 0; TimesChildTestMessageHandled = 0; ParentTestMessage = 0; Subscribe <TestMessage>(this); Subscribe <TestMessage2>(this); Subscribe <ChildTestMessage>(this); }
public static ReactiveCommand BuildFireCommand( this IGeneralBus bus, IObservable <bool> canExecute, Func <Command> commandFunc, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { return(FireCommands(bus, new[] { commandFunc }, canExecute, scheduler, userErrorMsg, responseTimeout, ackTimeout)); }
protected TcpBusSide( IPAddress hostIp, int commandPort, IGeneralBus messageBus) { _hostIp = hostIp; _commandPort = commandPort; MessageBus = messageBus; StatsTimer = new Timer(60000); // getting the stats takes a while - only do it once a minute StatsTimer.Elapsed += _statsTimer_Elapsed; StatsTimer.Enabled = true; }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { RedirectToNull = true; _target = null; } _disposed = true; }
public EventStoreBusConnector( IGeneralBus bus, IEventStoreConnection es, string stream, string name) { _es = es; _stream = stream; _bus = new BusAdapter(bus); _name = name; _bus.Subscribe(this); _es.SubscribeToStreamAsync(stream, true, EventAppeared, SubscriptionDropped); }
public EventStoreBusConnector( IGeneralBus bus, IEventStoreHttpConnection conn, string stream, string name) { _conn = conn; _subscriber = EventStreamSubscriber.Create(_conn, HandleJsonEvent, new MemoryBackedStreamPositionRepositoryForDebugging()); _stream = stream; _name = name; _bus = new BusAdapter(bus); _bus.Subscribe(this); _subscriber.SubscribeTo(stream); }
protected CommandBusSpecification() { Bus = new CommandBus("Fixture Bus", slowMsgThreshold: TimeSpan.FromMilliseconds(500)); LocalBus = new CommandBus("Fixture LocalBus"); TestQueue = new TestQueue(Bus); try { Given(); When(); } catch (Exception) { throw; } }
public TcpBusClientSideTests() { _commandBus = new CommandBus("TestBus"); _hostAddress = IPAddress.Loopback; _clientAddress = IPAddress.Loopback; _clientTcpConnection = MockTcpConnection.CreateConnectingTcpConnection(Guid.NewGuid(), new IPEndPoint(_hostAddress, CommandPort), new TcpClientConnector(), TimeSpan.FromSeconds(120), conn => { }, (conn, err) => { }, verbose: true); }
public EventStoreMessageLogger( IGeneralBus bus, IEventStoreConnection es, string logStreamPrefix = "", bool enableLogging = false, bool idempotent = true) : base(bus, idempotent) { _bus = bus; _eventStore = es; Enabled = enableLogging; _streamPrefix = logStreamPrefix; if (Enabled) { _eventStore?.ConnectAsync(); } Subscribe <Message>(this); }
protected CommandQueueSpecification( int queueCount = 1, int slowCmdMs = 500, int slowAckMs = 500) { Bus = new CommandBus( "Fixture Bus", slowCmdThreshold: TimeSpan.FromMilliseconds(slowCmdMs), slowMsgThreshold: TimeSpan.FromMilliseconds(slowAckMs)); Queue = new MultiQueuedHandler( queueCount, index => new QueuedHandler( new AdHocHandler <Message>( msg => { if (msg is Command) { Bus.TryFire((Command)msg); } else { Bus.Publish(msg); } }), $"Queue {index}" ) ); Queue.Start(); TestQueue = new TestQueue(Bus); try { Given(); When(); } catch (Exception) { throw; } }
public MainWindowViewModel( IGeneralBus bus, AccountRM accountRm, Guid accountId) : base(bus) { _bus = bus; _accountRm = accountRm; _accountId = accountId; Output = new ReactiveList <string>() { "Initial balance: $0.00" }; AddCreditOrDebitCommand = CommandBuilder.FromAction( canExecute: this.WhenAnyValue(x => x.Amount, x => x > 0), action: () => { try { FireCreditOrDebit(); } catch (Exception e) { //Application.Current.Dispatcher.Invoke(() => Output.Add(e.Message)); } }); _accountRm? .AccountUpdateMessage .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(m => { if (m != null) { Output.Add(m); } }); }
public void Run(StartupEventArgs args) { _bus = new CommandBus( "Main Bus", false, TimeSpan.FromMinutes(1), // TODO: Eliminate these timeouts and add the necessary timeouts to commands on a per-command basis. TimeSpan.FromMinutes(1)); Configure(_bus); _bus.Fire(new CreateAccount( Bootstrap.NewAccountId, "TheAccount", Guid.NewGuid(), Guid.Empty)); _accountRm = new AccountRM(NewAccountId); var mainWindow = new MainWindow() { ViewModel = new MainWindowViewModel(_bus, _accountRm, NewAccountId) }; mainWindow.Show(); }
public BusAdapter(IGeneralBus bus) { _idTracker = null; _bus = bus; _trackedMessages = new HashSet <Guid>(); }