public static void Bootstrap() { RegisterServiceBus(); var bus = ObjectFactory.GetInstance <IServiceBus>(); bus.Subscribe <RequestStockQuote>(request => { //ThreadUtil.Sleep(20.Milliseconds()); bus.Publish(new StockQuoteReceivedImpl { Symbol = request.Symbol, Bid = 200.00m, Ask = 201.00m, Last = 200.50m, }); }); bus.Subscribe <StockQuoteRequestActor>(); RegisterRoutes(); PipelineViewer.Trace(bus.InboundPipeline); }
public void I_want_to_display_a_more_detailed_flow() { _pipeline.Filter <object>(m => true); _pipeline.Subscribe <PingMessage>(m => { }, x => { return(true); }); PipelineViewer.Trace(_pipeline); }
protected override void EstablishContext() { base.EstablishContext(); _sagaId = Guid.NewGuid(); _repository = SetupSagaRepository <SimpleSaga>(ObjectBuilder); _initiateSimpleSagaUnsubscribe = MockRepository.GenerateMock <UnsubscribeAction>(); _completeSimpleSagaUnsubscribe = MockRepository.GenerateMock <UnsubscribeAction>(); _subscriptionEvent = MockRepository.GenerateMock <ISubscriptionEvent>(); _subscriptionEvent.Expect(x => x.SubscribedTo <InitiateSimpleSaga>()).Repeat.Any().Return(() => { _initiateSimpleSagaUnsubscribe(); return(true); }); _subscriptionEvent.Expect(x => x.SubscribedTo <CompleteSimpleSaga>()).Repeat.Any().Return(() => { _completeSimpleSagaUnsubscribe(); return(true); }); LocalBus.InboundPipeline.Configure(x => x.Register(_subscriptionEvent)); _remove = LocalBus.Subscribe <SimpleSaga>(); PipelineViewer.Trace(LocalBus.InboundPipeline); }
public void The_pipeline_viewer_should_show_the_distributor() { PipelineViewer.Trace(LocalBus.InboundPipeline); PipelineViewer.Trace(LocalBus.ControlBus.InboundPipeline); PipelineViewer.Trace(RemoteBus.InboundPipeline); PipelineViewer.Trace(Instances["A"].DataBus.InboundPipeline); }
public void The_pipeline_should_have_insertable_items() { // two consumers, one for each type of message IndiscriminantConsumer <PingMessage> pingConsumer = new IndiscriminantConsumer <PingMessage>(); IndiscriminantConsumer <PongMessage> pongConsumer = new IndiscriminantConsumer <PongMessage>(); UnsubscribeAction pingToken = _pipeline.Subscribe(pingConsumer); UnsubscribeAction pongToken = _pipeline.Subscribe(pongConsumer); PipelineViewer.Trace(_pipeline); PingMessage pingMessage = new PingMessage(); PongMessage pongMessage = new PongMessage(); _pipeline.Dispatch(pingMessage, accept => true); _pipeline.Dispatch(pongMessage, accept => true); Assert.AreEqual(pingMessage, pingConsumer.Consumed); Assert.AreEqual(pongMessage, pongConsumer.Consumed); pingToken(); pongToken(); PipelineViewer.Trace(_pipeline); }
public void PipelineBuilding() { var builder = MockRepository.GenerateMock <IObjectBuilder>(); MessagePipeline pipeline = MessagePipelineConfigurator.CreateDefault(builder, null); pipeline.Subscribe <MetadataConsumer>(); pipeline.Subscribe <MetadataPConsumer>(); PipelineViewer.Trace(pipeline); }
public void Heartbeat_subscriptions_should_be_kept_on_the_control_bus() { Console.WriteLine("data bus"); PipelineViewer.Trace(_serviceBus.OutboundPipeline); Console.WriteLine("control bus"); PipelineViewer.Trace(_serviceBus.ControlBus.OutboundPipeline); _serviceBus.ControlBus.ShouldHaveRemoteSubscriptionFor <Heartbeat>(); }
public void Start() { _log.Info("Health Service Starting"); _unsubscribeToken += _bus.Subscribe(this); _unsubscribeToken += _bus.Subscribe <HealthSaga>(); PipelineViewer.Trace(_bus.InboundPipeline); _log.Info("Health Service Started"); }
public void A_state_machine_based_saga_should_automatically_wire_up_subscriptions() { RemoteBus.Subscribe <AutoStateMachineSaga>(); PipelineViewer.Trace(RemoteBus.InboundPipeline); PipelineViewer.Trace(RemoteBus.OutboundPipeline); Assert.AreEqual(0, _repository.Where(x => true).Count()); RemoteBus.Publish(new RegisterUser(_transactionId, _username, _password, _displayName, _email)); for (int i = 0; i < 20; i++) { if (_repository.Where(x => true).Count() == 1) { break; } Thread.Sleep(100); } Assert.AreEqual(1, _repository.Where(x => true).Count()); foreach (AutoStateMachineSaga saga in _repository.Where(x => true)) { saga.CurrentState.ShouldEqual(AutoStateMachineSaga.WaitingForEmailValidation); } _repository .Where(x => x.CorrelationId == _transactionId) .Select(x => x.CurrentState) .First() .ShouldEqual(AutoStateMachineSaga.WaitingForEmailValidation); RemoteBus.Publish(new UserValidated(_transactionId)); for (int i = 0; i < 20; i++) { if (_repository.Where(x => x.CorrelationId == _transactionId).Select(x => x.CurrentState).First() == AutoStateMachineSaga.Completed) { break; } Thread.Sleep(100); } _repository .Where(x => x.CorrelationId == _transactionId) .Select(x => x.CurrentState) .First() .ShouldEqual(AutoStateMachineSaga.Completed); }
protected override void EstablishContext() { base.EstablishContext(); _sagaId = Guid.NewGuid(); _repository = SetupSagaRepository <SimpleSaga>(ObjectBuilder); _remove = LocalBus.Subscribe <SimpleSaga>(); PipelineViewer.Trace(LocalBus.InboundPipeline); }
public void Should_deliver_the_message_to_an_interested_consumer() { var first = new Future <FirstMessageContract>(); RemoteBus.Subscribe <FirstMessageContract>(first.Complete); PipelineViewer.Trace(RemoteBus.InboundPipeline); var message = new SomeMessageContract("Joe", 27); LocalBus.Publish(message); first.IsAvailable(1.Seconds()).ShouldBeTrue(); }
public void Removing_a_subscription_twice_should_not_have_a_negative_impact() { Guid clientId = CombGuid.Generate(); var subscription = new SubscriptionInformation(clientId, 1, typeof(PingMessage), RemoteBus.Endpoint.Uri); LocalControlBus.Endpoint.Send(new AddSubscription(subscription)); Thread.Sleep(250); LocalControlBus.Endpoint.Send(new RemoveSubscription(subscription)); LocalControlBus.Endpoint.Send(new RemoveSubscription(subscription)); Thread.Sleep(250); PipelineViewer.Trace(LocalBus.OutboundPipeline); }
public void A_batch_component_should_be_delivered_messages() { var consumer = new TestBatchConsumer <IndividualBatchMessage, Guid>(); _builder.Stub(x => x.GetInstance <TestBatchConsumer <IndividualBatchMessage, Guid> >()).Return(consumer); _pipeline.Subscribe <TestBatchConsumer <IndividualBatchMessage, Guid> >(); PipelineViewer.Trace(_pipeline); PublishBatch(_pipeline, 1); TimeSpan _timeout = 5.Seconds(); TestBatchConsumer <IndividualBatchMessage, Guid> .AnyShouldHaveReceivedBatch(_batchId, _timeout); }
public void A_message_should_fall_throuh_happy_filters() { var consumer = new TestMessageConsumer <PingMessage>(); _pipeline.Filter <PingMessage>(x => true); _pipeline.Subscribe(consumer); var message = new PingMessage(); _pipeline.Dispatch(message); consumer.ShouldHaveReceivedMessage(message); PipelineViewer.Trace(_pipeline); }
public void A_filter_should_be_nameable() { var consumer = new TestMessageConsumer <PingMessage>(); _pipeline.Filter <PingMessage>("Message Blocker", x => false); _pipeline.Subscribe(consumer); var message = new PingMessage(); _pipeline.Dispatch(message); consumer.ShouldNotHaveReceivedMessage(message); PipelineViewer.Trace(_pipeline); }
public void A_component_should_be_subscribed_to_the_pipeline() { var consumer = new TestMessageConsumer <PingMessage>(); _pipeline.ConnectConsumer <TestMessageConsumer <PingMessage> >(() => consumer); PipelineViewer.Trace(_pipeline); var message = new PingMessage(); _pipeline.ShouldHaveSubscriptionFor <PingMessage>(); _pipeline.Dispatch(message); TestMessageConsumer <PingMessage> .AnyShouldHaveReceivedMessage(message, 1.Seconds()); }
public void An_object_filter_should_pass_the_message_if_allowed() { var consumer = new TestMessageConsumer <object>(); _pipeline.Filter <object>("Message Passer", x => true); _pipeline.Subscribe(consumer); var message = new PingMessage(); _pipeline.Dispatch(message); consumer.ShouldHaveReceivedMessage(message); PipelineViewer.Trace(_pipeline); }
public void A_filtered_message_should_not_be_received() { TestMessageConsumer <PingMessage> consumer = new TestMessageConsumer <PingMessage>(); _pipeline.Filter <PingMessage>(x => false); _pipeline.Subscribe(consumer); PingMessage message = new PingMessage(); _pipeline.Dispatch(message); consumer.ShouldNotHaveReceivedMessage(message); PipelineViewer.Trace(_pipeline); }
public void A_selective_component_should_properly_handle_the_love() { ParticularConsumer consumer = MockRepository.GenerateMock <ParticularConsumer>(); _pipeline.ConnectConsumer <ParticularConsumer>(() => consumer); PipelineViewer.Trace(_pipeline); var message = new PingMessage(); consumer.Expect(x => x.Accept(message)).Return(true); consumer.Expect(x => x.Consume(message)); _pipeline.Dispatch(message); consumer.VerifyAllExpectations(); }
public void The_endpoint_consumer_should_be_returned() { IEndpoint endpoint = MockRepository.GenerateMock <IEndpoint>(); endpoint.Stub(x => x.Uri).Return(new Uri("msmq://localhost/queue_name")); _pipeline.Subscribe <PingMessage>(endpoint); PipelineViewer.Trace(_pipeline); PingMessage message = new PingMessage(); endpoint.Expect(x => x.Send(message)); _pipeline.Dispatch(message); endpoint.VerifyAllExpectations(); }
public void A_batch_consumer_should_be_delivered_a_lot_of_messages() { var batchConsumer = new TestBatchConsumer <IndividualBatchMessage, Guid>(x => PipelineViewer.Trace(_pipeline)); var removeSubscription = _pipeline.Subscribe(batchConsumer); PipelineViewer.Trace(_pipeline); PublishBatch(_pipeline, 100); TimeSpan _timeout = 5.Seconds(); batchConsumer.ShouldHaveReceivedBatch(_timeout); removeSubscription(); PipelineViewer.Trace(_pipeline); }
public void A_state_machine_based_saga_should_automatically_wire_up_subscriptions() { LocalBus.SubscribeSaga(_repository); PipelineViewer.Trace(LocalBus.InboundPipeline); PipelineViewer.Trace(LocalBus.OutboundPipeline); LocalBus.Publish(new RegisterUser(_transactionId, _username, _password, _displayName, _email)); AutoStateMachineSaga saga = _repository.ShouldContainSaga(_transactionId, 8.Seconds()); saga.CurrentState.ShouldEqual(AutoStateMachineSaga.WaitingForEmailValidation); LocalBus.Publish(new UserValidated(_transactionId)); saga.ShouldBeInState(AutoStateMachineSaga.Completed, 8.Seconds()); }
public void Should_deliver_the_message_to_an_both_interested_consumers() { var first = new Future <FirstMessageContract>(); var second = new Future <SecondMessageContract>(); // These can't be on the same bus, because we only send a message to an endpoint once // maybe we can do something here by changing the outbound context to keep track of tmessage/endpoint uri RemoteBus.Subscribe <FirstMessageContract>(first.Complete); LocalBus.Subscribe <SecondMessageContract>(second.Complete); PipelineViewer.Trace(RemoteBus.InboundPipeline); var message = new SomeMessageContract("Joe", 27); LocalBus.Publish(message); first.IsAvailable(1.Seconds()).ShouldBeTrue(); second.IsAvailable(1.Seconds()).ShouldBeTrue(); }
public void A_component_should_be_subscribed_to_the_pipeline() { TestMessageConsumer <PingMessage> consumer = MockRepository.GenerateMock <TestMessageConsumer <PingMessage> >(); _builder.Expect(x => x.GetInstance <TestMessageConsumer <PingMessage> >()).Return(consumer).Repeat.Once(); _pipeline.Subscribe <TestMessageConsumer <PingMessage> >(); PipelineViewer.Trace(_pipeline); PingMessage message = new PingMessage(); consumer.Expect(x => x.Consume(message)); _pipeline.Dispatch(message); consumer.VerifyAllExpectations(); _builder.VerifyAllExpectations(); }
public void A_selective_component_should_properly_handle_the_love() { ParticularConsumer consumer = MockRepository.GenerateMock <ParticularConsumer>(); _builder.Expect(x => x.GetInstance <ParticularConsumer>()).Return(consumer).Repeat.Once(); _pipeline.Subscribe <ParticularConsumer>(); PipelineViewer.Trace(_pipeline); PingMessage message = new PingMessage(); consumer.Expect(x => x.Accept(message)).Return(true); consumer.Expect(x => x.Consume(message)); _pipeline.Dispatch(message); consumer.VerifyAllExpectations(); _builder.VerifyAllExpectations(); }
public void A_component_should_be_subscribed_to_multiple_messages_on_the_pipeline() { PingPongConsumer consumer = MockRepository.GenerateMock <PingPongConsumer>(); _pipeline.ConnectConsumer <PingPongConsumer>(() => consumer); PipelineViewer.Trace(_pipeline); var ping = new PingMessage(); consumer.Expect(x => x.Consume(ping)); _pipeline.Dispatch(ping); var pong = new PongMessage(ping.CorrelationId); consumer.Expect(x => x.Consume(pong)); _pipeline.Dispatch(pong); consumer.VerifyAllExpectations(); }
public void The_endpoint_consumer_should_be_returned() { var endpoint = MockRepository.GenerateMock <IEndpoint>(); endpoint.Stub(x => x.Address.Uri).Return(new Uri("rabbitmq://localhost/queue_name")); _pipeline.ConnectEndpoint <PingMessage>(endpoint); PipelineViewer.Trace(_pipeline); var message = new PingMessage(); ISendContext <PingMessage> context = new SendContext <PingMessage>(message); endpoint.Expect(x => x.Send(context)).IgnoreArguments(); _pipeline.Dispatch(message); endpoint.VerifyAllExpectations(); }
private void DumpPipelines() { Trace.WriteLine("LocalBus.InboundPipeline"); PipelineViewer.Trace(LocalBus.InboundPipeline); Trace.WriteLine("LocalBus.OutboundPipeline"); PipelineViewer.Trace(LocalBus.OutboundPipeline); Trace.WriteLine("RemoteBus.InboundPipeline"); PipelineViewer.Trace(RemoteBus.InboundPipeline); Trace.WriteLine("RemoteBus.OutboundPipeline"); PipelineViewer.Trace(RemoteBus.OutboundPipeline); Trace.WriteLine("SubscriptionBus.InboundPipeline"); PipelineViewer.Trace(SubscriptionBus.InboundPipeline); Trace.WriteLine("SubscriptionBus.OutboundPipeline"); PipelineViewer.Trace(SubscriptionBus.OutboundPipeline); }
public void ConfigurationTest() { var cfg = new RoutingConfigurator(); cfg.Route <PingMessage>().To(_address); cfg.Route <PongMessage>().To(_address); IBusService c = cfg.Create(_bus, _builder); PipelineViewer.Trace(_pipeline); c.Start(_bus); PipelineViewer.Trace(_pipeline); c.Stop(); PipelineViewer.Trace(_pipeline); }
public void Should_dispatch_an_interface_via_the_pipeline() { var builder = MockRepository.GenerateMock <IObjectBuilder>(); var pipeline = MessagePipelineConfigurator.CreateDefault(builder, null); var consumer = new TestMessageConsumer <ComplaintAdded>(); var unsubscribeAction = pipeline.Subscribe(consumer); var user = new UserImpl("Chris", "*****@*****.**"); ComplaintAdded complaint = new ComplaintAddedImpl(user, "No toilet paper", BusinessArea.Appearance) { Body = "There was no toilet paper in the stall, forcing me to use my treasured issue of .NET Developer magazine." }; pipeline.Dispatch(complaint); PipelineViewer.Trace(pipeline); consumer.ShouldHaveReceivedMessage(complaint); }