public void A_selective_component_should_properly_handle_the_love() { ParticularConsumer consumer = MockRepository.GenerateMock <ParticularConsumer>(); _pipeline.ConnectConsumer <ParticularConsumer>(() => consumer); 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(); }
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 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 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 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_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(); }
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 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(); }
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); }
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { var bus = (ServiceBus)objectProvider.GetObject(); using (var displayForm = new ServiceBusForm()) { displayForm.Text = "hi"; var sb = new StringBuilder(); sb.AppendLine(string.Format("Listening On: {0}", bus.Endpoint)); sb.AppendLine("Outbound Pipeline:"); PipelineViewer.Trace(bus.OutboundPipeline); sb.AppendLine("Inbound Pipeline:"); PipelineViewer.Trace(bus.InboundPipeline); displayForm.SetContent(sb.ToString()); windowService.ShowDialog(displayForm); } }
public static void ShouldHaveRemoteSubscriptionFor <TMessage>(this IServiceBus bus) { DateTime giveUpAt = DateTime.Now + Timeout; while (DateTime.Now < giveUpAt) { var inspector = new EndpointSinkLocator(typeof(TMessage)); bus.OutboundPipeline.Inspect(inspector); if (inspector.DestinationAddress != null) { return; } Thread.Sleep(20); } PipelineViewer.Trace(bus.OutboundPipeline, text => _log.ErrorFormat("Pipeline Inspection Result: " + text)); Assert.Fail("A subscription for " + typeof(TMessage).ToFriendlyName() + " was not found on " + bus.Endpoint.Address.Uri); }
public void A_filter_should_be_removable() { var consumer = new TestMessageConsumer <PingMessage>(); var f = _pipeline.Filter <PingMessage>(x => false); PipelineViewer.Trace(_pipeline); var message = new PingMessage(); _pipeline.Dispatch(message); consumer.ShouldNotHaveReceivedMessage(message); f(); PipelineViewer.Trace(_pipeline); message = new PingMessage(); _pipeline.Dispatch(message); consumer.ShouldHaveReceivedMessage(message); }
public void Correlated_subscriptions_should_make_happy_sounds() { var message = new PingMessage(); var consumer = new TestCorrelatedConsumer <PingMessage, Guid>(message.CorrelationId); var negativeConsumer = new TestCorrelatedConsumer <PingMessage, Guid>(Guid.Empty); var token = _pipeline.ConnectInstance(consumer); token += _pipeline.ConnectInstance(negativeConsumer); PipelineViewer.Trace(_pipeline); _pipeline.Dispatch(message); consumer.ShouldHaveReceivedMessage(message, 0.Seconds()); negativeConsumer.ShouldNotHaveReceivedMessage(message, 0.Seconds()); token(); PipelineViewer.Trace(_pipeline); }
public void A_bunch_of_mixed_subscriber_types_should_work() { var consumer = new IndiscriminantConsumer <PingMessage>(); var consumerYes = new ParticularConsumer(true); var consumerNo = new ParticularConsumer(false); Stopwatch firstTime = Stopwatch.StartNew(); var unsubscribeToken = _pipeline.ConnectInstance(consumer); firstTime.Stop(); Stopwatch secondTime = Stopwatch.StartNew(); unsubscribeToken += _pipeline.ConnectInstance(consumerYes); secondTime.Stop(); unsubscribeToken += _pipeline.ConnectInstance(consumerNo); Trace.WriteLine(string.Format("First time: {0}, Second Time: {1}", firstTime.Elapsed, secondTime.Elapsed)); PipelineViewer.Trace(_pipeline); var message = new PingMessage(); _pipeline.Dispatch(message); Assert.AreEqual(message, consumer.Consumed); Assert.AreEqual(message, consumerYes.Consumed); Assert.AreEqual(null, consumerNo.Consumed); unsubscribeToken(); var nextMessage = new PingMessage(); _pipeline.Dispatch(nextMessage); Assert.AreEqual(message, consumer.Consumed); Assert.AreEqual(message, consumerYes.Consumed); }
public void A_state_machine_should_respond_to_combined_events() { LocalBus.SubscribeSaga(_repository); PipelineViewer.Trace(LocalBus.InboundPipeline); PipelineViewer.Trace(LocalBus.OutboundPipeline); LocalBus.Publish(new Second { CorrelationId = _transactionId }); CombineSaga saga = _repository.ShouldContainSaga(_transactionId, 8.Seconds()); saga.ShouldBeInState(CombineSaga.Initial); saga.Combined.ShouldEqual(2); LocalBus.Publish(new First { CorrelationId = _transactionId }); saga.ShouldBeInState(CombineSaga.Completed); saga.Combined.ShouldEqual(3); }
protected override void EstablishContext() { base.EstablishContext(); _sagaId = Guid.NewGuid(); _repository = SetupSagaRepository <TestSaga>(ObjectBuilder); _initiateSimpleSagaUnsubscribeCalled = false; _completeSimpleSagaUnsubscribeCalled = false; _initiateSimpleSagaUnsubscribe = () => { _initiateSimpleSagaUnsubscribeCalled = true; return(true); }; _completeSimpleSagaUnsubscribe = () => { _completeSimpleSagaUnsubscribeCalled = true; return(true); }; _subscriptionEvent = MockRepository.GenerateMock <ISubscriptionEvent>(); _subscriptionEvent.Expect(x => x.SubscribedTo <InitiateSimpleSaga>()).Repeat.Any().Return(_initiateSimpleSagaUnsubscribe); _subscriptionEvent.Expect(x => x.SubscribedTo <CompleteSimpleSaga>()).Repeat.Any().Return(_completeSimpleSagaUnsubscribe); LocalBus.InboundPipeline.Configure(x => x.Register(_subscriptionEvent)); _remove = LocalBus.Subscribe <TestSaga>(); PipelineViewer.Trace(LocalBus.InboundPipeline); }
public void A_component_should_be_subscribed_to_multiple_messages_on_the_pipeline() { PingPongConsumer consumer = MockRepository.GenerateMock <PingPongConsumer>(); _builder.Expect(x => x.GetInstance <PingPongConsumer>()).Return(consumer).Repeat.Twice(); _pipeline.Subscribe <PingPongConsumer>(); PipelineViewer.Trace(_pipeline); PingMessage ping = new PingMessage(); consumer.Expect(x => x.Consume(ping)); _pipeline.Dispatch(ping); PongMessage pong = new PongMessage(ping.CorrelationId); consumer.Expect(x => x.Consume(pong)); _pipeline.Dispatch(pong); _builder.VerifyAllExpectations(); consumer.VerifyAllExpectations(); }
public void AuctionSaga_Created_When_CreateAuction_Received_And_Transitioned_To_OpenState() { _context.CorrelationId = NewId.NextGuid(); _context.AuctionId = NewId.NextGuid(); PipelineViewer.Trace(_context.LocalBus.InboundPipeline); PipelineViewer.Trace(_context.LocalBus.OutboundPipeline); var message = new CreateAuction() { CorrelationId = _context.CorrelationId, AuctionId = _context.AuctionId }; _context.LocalBus.Publish(message); var saga = _context.Repository.ShouldContainSaga(_context.CorrelationId); saga.ShouldBeInState(AuctionSaga.Open); }
public static void Bootstrap() { var bus = ObjectFactory.GetInstance <IServiceBus>(); bus.Subscribe <OrderDetailRequestActor>(); bus.Subscribe <RetrieveOrderDetails>(message => { var details = new OrderDetailsReceivedImpl(message.CustomerId, message.OrderId, SystemUtil.Now, OrderStatus.Accepted); // TODO // impl builder // var message = BuildImpl<ODR>(x => // { x.Set(y => y.CustomerId, customerId) // } CurrentMessage.Respond(details); }); PipelineViewer.Trace(bus.InboundPipeline); }
public static void Trace <T>(this IPipelineSink <T> pipeline) where T : class { PipelineViewer.Trace(pipeline); }
public static void View <T>(this IPipelineSink <T> pipeline, Action <string> callback) where T : class { PipelineViewer.Trace(pipeline, callback); }
public void The_pipeline_viewer_should_show_the_distributor() { PipelineViewer.Trace(LocalBus.InboundPipeline); PipelineViewer.Trace(Instances["A"].DataBus.InboundPipeline); }
public void I_want_to_display_the_entire_flow_through_the_pipeline() { PipelineViewer.Trace(_pipeline); }
public override void Run() { // This is a sample worker implementation. Replace with your logic. _logger.Info("starting receiver"); RoleEnvironment.Stopping += (sender, args) => _isStopping = true; ConfigureDiagnostics(); var stopping = new AutoResetEvent(false); long rampUp = Convert.ToInt32(RoleEnvironment.GetConfigurationSettingValue("RampUpCount")); long sampleSize = Convert.ToInt32(RoleEnvironment.GetConfigurationSettingValue("SampleSize")); long failures = 0; long received = 0; var watch = new Stopwatch(); var datapoints = new LinkedList <DataPoint>(); var senders = new LinkedList <IEndpoint>(); var maxSenders = Convert.ToInt32(RoleEnvironment.GetConfigurationSettingValue("WaitForNumberOfSenders")); var allSendersUp = new CountdownEvent(maxSenders); var creds = new AccountDetails(); using (var sb = ServiceBusFactory.New(sbc => { sbc.ReceiveFrom(creds.BuildUri("receiver")); sbc.SetPurgeOnStartup(true); sbc.UseNLog(); sbc.UseAzureServiceBus(); sbc.UseAzureServiceBusRouting(); })) { UnsubscribeAction unsubscribeMe = null; unsubscribeMe += sb.SubscribeHandler <SenderUp>(su => { _logger.Info("received SenderUp!"); lock (senders) { var endpoint = sb.GetEndpoint(su.Source); if (!senders.Any(x => x.Address.Uri.Equals(endpoint.Address.Uri)) && allSendersUp.CurrentCount < maxSenders) { senders.AddLast(endpoint); allSendersUp.Signal(); } } }); _logger.Info("waiting for all senders ..."); allSendersUp.Wait(); _logger.Info("sending 'ReadySetGo' to all senders"); lock (senders) senders.Each(sender => sender.Send <ReadySetGo>(new {})); //unsubscribeMe = sb.SubscribeHandler<IConsumeContext<ZoomZoom>>(consumeContext => unsubscribeMe += sb.SubscribeHandler <ZoomZoom>(payment => { //var payment = consumeContext.Message; long currentReceived; if ((currentReceived = Interlocked.Increment(ref received)) == rampUp) { watch.Start(); } else if (currentReceived < rampUp) { return; } var localFailures = new long?(); if (Math.Abs(payment.Amount - 1024m) > 0.0001m) { localFailures = Interlocked.Increment(ref failures); } if (currentReceived + rampUp == sampleSize || _isStopping) { unsubscribeMe(); watch.Stop(); stopping.Set(); } if (currentReceived % 100 == 0) { var point = new DataPoint { Received = currentReceived, Ticks = watch.ElapsedTicks, Failures = localFailures ?? failures, SampleMessage = payment, Instance = DateTime.UtcNow /* assume all prev 100 msgs same size */ //Size = consumeContext.BaseContext.BodyStream.Length * 100 }; lock (datapoints) datapoints.AddLast(point); _logger.Debug(string.Format("Logging {0}", point)); } }); PipelineViewer.Trace(sb.InboundPipeline); _logger.Info("waiting for all messages!"); stopping.WaitOne(); sb.GetEndpoint(creds.BuildUri("sender")).Send <ZoomDone>(new{}); } _logger.Info( string.Format(@" Performance Test Done ===================== Total messages received: {0} Time taken: {1} of which: Corrupt messages count: {2} Valid messages count: {3} metrics: Message per second: {4} Total bytes transferred:{5} All samples' data equal:{6} data points: {7} ", sampleSize, watch.Elapsed, failures, sampleSize - failures, 1000d * sampleSize / (double)watch.ElapsedMilliseconds, datapoints.Sum(dp => dp.Size), datapoints.Select(x => x.SampleMessage).All(x => x.Payload.Equals(TestData.PayloadMessage, StringComparison.InvariantCulture)), datapoints.Aggregate("", (str, dp) => str + dp.ToString() + Environment.NewLine))); _logger.Info("Idling... aka. softar."); while (true) { Thread.Sleep(10000); } // now have a look in Server Explorer, WADLogsTable, w/ Filter similar to "Timestamp gt datetime'2012-02-03T10:06:50Z'" // (if this isn't your first deployment, or no filter if you feel like that) }