private async Task <BrokeredMessage> When(BrokeredMessageFactory brokeredMessageFactory) { var bigFatObject = new string(Enumerable.Range(0, 256 * 1024).Select(i => '.').ToArray()); var nimbusMessage = new NimbusMessage("noPath", bigFatObject); return(await brokeredMessageFactory.BuildBrokeredMessage(nimbusMessage)); }
private async Task NotifyTopic(string topicName, object @event) { var client = TopicClient.CreateFromConnectionString(this.serviceBusConfiguration.ConnectionString, this.serviceBusConfiguration.OrderCreatedTopicName); var msg = BrokeredMessageFactory.CreateJsonMessage(@event); await client.SendAsync(msg); }
protected MessageDispatcherTestBase() { var clock = Substitute.For <IClock>(); var replyQueueNameSetting = new ReplyQueueNameSetting( new ApplicationNameSetting { Value = "TestApplication" }, new InstanceNameSetting { Value = "TestInstance" }); TypeProvider = new TestHarnessTypeProvider(new[] { GetType().Assembly }, new[] { GetType().Namespace }); var serializer = new DataContractSerializer(TypeProvider); HandlerMapper = new HandlerMapper(TypeProvider); BrokeredMessageFactory = new BrokeredMessageFactory(new DefaultMessageTimeToLiveSetting(), new MaxLargeMessageSizeSetting(), new MaxSmallMessageSizeSetting(), replyQueueNameSetting, clock, new NullCompressor(), new DispatchContextManager(), new UnsupportedLargeMessageBodyStore(), serializer, TypeProvider); }
public void TheExceptionIsBubbledBackThroughTheInterceptors() { var interceptor = Substitute.For <IInboundInterceptor>(); interceptor .When(x => x.OnCommandHandlerExecuting(Arg.Any <EmptyCommand>(), Arg.Any <BrokeredMessage>())) .Do(x => { throw new Exception("Ruh roh"); }); var dispatcher = GetCommandMessageDispatcher <EmptyCommand, EmptyCommandHandler>(interceptor); var brokeredMessage = BrokeredMessageFactory.Create(new EmptyCommand()).Result; try { dispatcher.Dispatch(brokeredMessage).Wait(); } catch (AggregateException) { // Dispatch rethrows the exception, don't care } interceptor .Received() .OnCommandHandlerError(Arg.Any <EmptyCommand>(), brokeredMessage, Arg.Any <Exception>()); }
internal static void Dispose(this BrokeredMessageFactory messagingFactory) { try { //messagingFactory.Close(); } catch { // we don't care. It's already borked. We just want it to go away and release its connection. } }
public void TheExceptionIsBubbledThroughTheInterceptors() { var interceptor = Substitute.For <IInboundInterceptor>(); var dispatcher = GetRequestMessageDispatcher <ExceptingRequest, ExceptingResponse, ExceptingRequestHandler>(interceptor); var brokeredMessage = BrokeredMessageFactory.Create(new ExceptingRequest()).Result; dispatcher.Dispatch(brokeredMessage).Wait(); interceptor .Received() .OnRequestHandlerError(Arg.Any <ExceptingRequest>(), brokeredMessage, Arg.Any <Exception>()); }
public void TheExceptionIsBubbledBackThroughTheInterceptors() { var interceptor = Substitute.For <IInboundInterceptor>(); interceptor .When(x => x.OnRequestHandlerExecuting(Arg.Any <EmptyRequest>(), Arg.Any <BrokeredMessage>())) .Do(x => { throw new Exception("Ruh roh"); }); var dispatcher = GetRequestMessageDispatcher <EmptyRequest, EmptyResponse, EmptyRequestHandler>(interceptor); var brokeredMessage = BrokeredMessageFactory.Create(new EmptyRequest()).Result; dispatcher.Dispatch(brokeredMessage).Wait(); interceptor .Received() .OnRequestHandlerError(Arg.Any <EmptyRequest>(), brokeredMessage, Arg.Any <Exception>()); }
public async Task <IActionResult> Create([FromBody] CreateOrderCommand command) { if (command == null) { return(this.BadRequest("Invalid commmand, ensure body has json payload")); } if (command.OrderId == Guid.Empty) { command.OrderId = Guid.NewGuid(); } var queueClient = QueueClient.CreateFromConnectionString(this.serviceBusConfiguration.ConnectionString, this.serviceBusConfiguration.CreateOrderQueueName); await queueClient.SendAsync(BrokeredMessageFactory.CreateJsonMessage(command)); return(CreatedAtAction(nameof(Get), new { orderId = command.OrderId }, command.OrderId)); }
internal static bool IsBorked(this BrokeredMessageFactory messagingFactory) { var isFaulted = (bool)_isFaultedProperty.GetValue(messagingFactory); if (isFaulted) { return(true); } var isClosedOrClosing = (bool)_isClosedOrClosingProperty.GetValue(messagingFactory); if (isClosedOrClosing) { return(true); } return(false); }
protected override Task <BusCommandSender> Given() { _nimbusMessageSender = Substitute.For <INimbusMessageSender>(); var messagingFactory = Substitute.For <INimbusMessagingFactory>(); messagingFactory.GetQueueSender(Arg.Any <string>()).Returns(ci => _nimbusMessageSender); var clock = new SystemClock(); var typeProvider = new TestHarnessTypeProvider(new[] { GetType().Assembly }, new[] { GetType().Namespace }); var serializer = new DataContractSerializer(typeProvider); var replyQueueNameSetting = new ReplyQueueNameSetting( new ApplicationNameSetting { Value = "TestApplication" }, new InstanceNameSetting { Value = "TestInstance" }); var brokeredMessageFactory = new BrokeredMessageFactory(new DefaultMessageTimeToLiveSetting(), new MaxLargeMessageSizeSetting(), new MaxSmallMessageSizeSetting(), replyQueueNameSetting, clock, new NullCompressor(), new DispatchContextManager(), new UnsupportedLargeMessageBodyStore(), serializer, typeProvider); var logger = Substitute.For <ILogger>(); var knownMessageTypeVerifier = Substitute.For <IKnownMessageTypeVerifier>(); var router = new DestinationPerMessageTypeRouter(); var dependencyResolver = new NullDependencyResolver(); var outboundInterceptorFactory = new NullOutboundInterceptorFactory(); var busCommandSender = new BusCommandSender(brokeredMessageFactory, dependencyResolver, knownMessageTypeVerifier, logger, messagingFactory, outboundInterceptorFactory, router); return(Task.FromResult(busCommandSender)); }
public void TheExceptionIsBubbledThroughTheInterceptors() { var interceptor = Substitute.For <IInboundInterceptor>(); var dispatcher = GetEventMessageDispatcher <ExceptingEvent, ExceptingEventHandler>(interceptor); var brokeredMessage = BrokeredMessageFactory.Create(new ExceptingEvent()).Result; try { dispatcher.Dispatch(brokeredMessage).Wait(); } catch (AggregateException) { // Dispatch rethrows the exception, don't care } interceptor .Received() .OnEventHandlerError(Arg.Any <ExceptingEvent>(), brokeredMessage, Arg.Any <Exception>()); }
protected override async Task <CommandMessageDispatcher> Given() { var clock = new SystemClock(); var logger = new ConsoleLogger(); var typeProvider = new TestHarnessTypeProvider(new[] { GetType().Assembly }, new[] { GetType().Namespace }); var serializer = new DataContractSerializer(typeProvider); var replyQueueNameSetting = new ReplyQueueNameSetting( new ApplicationNameSetting { Value = "TestApplication" }, new InstanceNameSetting { Value = "TestInstance" }); var handlerMap = new HandlerMapper(typeProvider).GetFullHandlerMap(typeof(IHandleCommand <>)); _brokeredMessageFactory = new BrokeredMessageFactory(new DefaultMessageTimeToLiveSetting(), new MaxLargeMessageSizeSetting(), new MaxSmallMessageSizeSetting(), replyQueueNameSetting, clock, new NullCompressor(), new DispatchContextManager(), new UnsupportedLargeMessageBodyStore(), serializer, typeProvider); return(new CommandMessageDispatcher(_brokeredMessageFactory, new SystemClock(), new DependencyResolver(typeProvider), new NullInboundInterceptorFactory(), new NullLogger(), handlerMap, new DefaultMessageLockDurationSetting(), new NimbusTaskFactory(new MaximumThreadPoolThreadsSetting(), new MinimumThreadPoolThreadsSetting(), logger), Substitute.For <IPropertyInjector>())); }
private async Task RaiseEvent(string productChangedTopicName, ProductChangedEvent productChangedEvent) { var topicClient = TopicClient.CreateFromConnectionString(this.serviceBusConfiguration.ConnectionString, this.serviceBusConfiguration.ProductChangedTopicName); await topicClient.SendAsync(BrokeredMessageFactory.CreateJsonMessage(productChangedEvent)); }
private async Task SendCommand(string queueName, object command) { var queueClient = QueueClient.CreateFromConnectionString(this.serviceBusConfiguration.ConnectionString, queueName); await queueClient.SendAsync(BrokeredMessageFactory.CreateJsonMessage(command)); }
private async Task <BrokeredMessage> When(BrokeredMessageFactory brokeredMessageFactory) { var bigFatObject = new string(Enumerable.Range(0, 256 * 1024).Select(i => '.').ToArray()); return(await brokeredMessageFactory.Create(bigFatObject)); }