protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _count = 0; _received = GetTask<ConsumeContext<PingMessage>>(); configurator.Handler<PingMessage>(async context => { if (_timer == null) _timer = Stopwatch.StartNew(); if (_count++ < 2) { Console.WriteLine("{0} now is not a good time", DateTime.UtcNow); await context.Defer(TimeSpan.FromMilliseconds(1000)); return; } _timer.Stop(); Console.WriteLine("{0} okay, now is good (retried {1} times)", DateTime.UtcNow, context.Headers.Get("MT-Redelivery-Count", default(int?))); // okay, ready. _receivedTimeSpan = _timer.Elapsed; _received.TrySetResult(context); }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { Handler<PingMessage>(configurator, context => { throw new IntentionalTestException("We want to be bad, so bad"); }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _count = 0; _received = GetTask<ConsumeContext<PingMessage>>(); configurator.Handler<PingMessage>(async context => { if (_timer == null) _timer = Stopwatch.StartNew(); if (_count++ < 2) { Console.WriteLine("{0} now is not a good time", DateTime.UtcNow); throw new IntentionalTestException("I'm so not ready for this jelly."); } _timer.Stop(); Console.WriteLine("{0} okay, now is good (retried {1} times)", DateTime.UtcNow, context.Headers.Get("MT-Redelivery-Count", default(int?))); // okay, ready. _receivedTimeSpan = _timer.Elapsed; _received.TrySetResult(context); }, x => x.UseDelayedRedelivery(Retry.Intervals(1000, 2000))); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureInputQueueEndpoint(configurator); _consumer = new ReconnectConsumer(TestTimeout); _consumer.Configure(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _first = Handler<FirstMessage>(configurator, async context => { await context.ScheduleMessage(DateTime.Now, new SecondMessage()); await context.ReceiveContext.CompleteTask; }); _second = Handled<SecondMessage>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _header = GetTask<ClaimsIdentity>(); _handled = Handler<PingMessage>(configurator, context => { _header.TrySetResult(context.Headers.Get<ClaimsIdentity>("Claims-Identity")); return TaskUtil.Completed; }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureInputQueueEndpoint(configurator); configurator.ConnectManagementEndpoint(_management); configurator.UseConcurrencyLimit(32, _management); _consumer = new TestConsumer(TestTimeout); _consumer.Configure(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureInputQueueEndpoint(configurator); _completed = Handled<JobCompleted>(configurator); configurator.Turnout<ProcessFile>(_busFactoryConfigurator, x => { x.SuperviseInterval = TimeSpan.FromSeconds(1); x.SetJobFactory(async context => await Task.Delay(context.Message.Size)); }); }
public static IRabbitMqReceiveEndpointConfigurator ConfigureConsumersForNinject( this IRabbitMqReceiveEndpointConfigurator ep, IEnumerable <Assembly> assembliesToScan, IKernel kernel) { //Scan all to get the consumers. var consumerInterface = typeof(IConsumer <>); foreach (var assembly in assembliesToScan) { var consumerTypes = assembly.GetModules() .SelectMany(m => m.GetTypes()) .Where( t => t.GetInterfaces() .Any(i => i.IsGenericType && !i.ContainsGenericParameters && i.GetGenericTypeDefinition() == consumerInterface)); foreach (var consumerType in consumerTypes) { var consumerTypeInterface = consumerType.GetInterfaces().FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == consumerInterface); var messageType = (consumerTypeInterface?.GenericTypeArguments)?.SingleOrDefault(i => typeof(IMessage).IsAssignableFrom(i)); var genericFaultHandlerType = typeof(TestGenericFaultConsumer <>); if (!kernel.GetBindings(consumerType).Any()) { kernel.Bind(consumerType).ToSelf(); } ep.Consumer(consumerType, type => kernel.Get(type)); if (messageType != null) { var faultHandler = genericFaultHandlerType.MakeGenericType(messageType); if (!kernel.GetBindings(faultHandler).Any()) { kernel.Bind(faultHandler).ToSelf(); } ep.Consumer(faultHandler, type => kernel.Get(type)); } } } return(ep); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureInputQueueEndpoint(configurator); _completed = Handled <JobCompleted>(configurator); configurator.Turnout <ProcessFile>(_busFactoryConfigurator, x => { x.SuperviseInterval = TimeSpan.FromSeconds(1); x.SetJobFactory(async context => await Task.Delay(context.Message.Size)); }); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _handled = Handled <A>(configurator); configurator.Bind(BoundExchange, x => { x.Durable = false; x.AutoDelete = true; x.ExchangeType = ExchangeType.Direct; x.RoutingKey = "bondage"; }); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.Handler <MyMessage>(async context => { await Console.Out.WriteLineAsync($"Received: {context.Message.Value}"); await context.Publish(new MyMessage2 { Value = context.Message.Value + " 2" }); await context.Publish(new MyMessage2()); // an exception will be caused by this action }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = Handled <RoutingSlipCompleted>(configurator); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext secondActivity = GetActivityContext <SecondTestActivity>(); _firstActivityCompleted = Handled <RoutingSlipActivityCompleted>(configurator, context => context.Message.ActivityName.Equals(testActivity.Name)); _secondActivityCompleted = Handled <RoutingSlipActivityCompleted>(configurator, context => context.Message.ActivityName.Equals(secondActivity.Name)); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = Handled <RoutingSlipCompleted>(configurator, x => x.Message.TrackingNumber == _routingSlip.TrackingNumber); var testActivity = GetActivityContext <TestActivity>(); var secondActivity = GetActivityContext <SecondTestActivity>(); _firstActivityCompleted = Handled <RoutingSlipActivityCompleted>(configurator, context => context.Message.ActivityName.Equals(testActivity.Name) && context.Message.TrackingNumber == _routingSlip.TrackingNumber); _secondActivityCompleted = Handled <RoutingSlipActivityCompleted>(configurator, context => context.Message.ActivityName.Equals(secondActivity.Name) && context.Message.TrackingNumber == _routingSlip.TrackingNumber); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.Consumer <TestHandler>(x => { x.Message <TestCommand>(m => { m.UseDelayedRedelivery(r => r.Interval(1, TimeSpan.FromMilliseconds(100))); m.UseRetry(r => r.Interval(1, TimeSpan.FromMilliseconds(100))); m.UseInMemoryOutbox(); }); }); }
protected override void ConfigureRabbitMqReceiveEndoint(IRabbitMqReceiveEndpointConfigurator configurator) { _ping = Handler <PingMessage>(configurator, async x => { var client = _factory.CreateRequestClient(x); await client.Request(new A(), x.CancellationToken); x.Respond(new PongMessage(x.Message.CorrelationId)); }); _a = Handler <A>(configurator, x => x.RespondAsync(new B())); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _consumer = new TestBatchConsumer(GetTask <Batch <PingMessage> >()); configurator.PrefetchCount = 10; configurator.Batch <PingMessage>(x => { x.MessageLimit = 5; x.Consumer(() => _consumer); }); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _ping = Handler <PingMessage>(configurator, async x => { RequestHandle <A> request = _clientFactory.CreateRequest(x, InputQueueAddress, new A(), x.CancellationToken); await request.GetResponse <B>(); x.Respond(new PongMessage(x.Message.CorrelationId)); }); _a = Handler <A>(configurator, x => x.RespondAsync(new B())); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.ConfigureConsumeTopology = false; _count = 0; configurator.Handler <PingMessage>(context => { Interlocked.Increment(ref _count); throw new IntentionalTestException(); }, x => x.UseDelayedRedelivery(r => r.Intervals(100, 200))); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.ConfigureConsumeTopology = false; base.ConfigureRabbitMqReceiveEndpoint(configurator); configurator.UseConcurrencyLimit(1); _consumer = new MultiTestConsumer(TestTimeout); _consumer.Consume <B>(); _consumer.Configure(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = GetTask<int>(); int count = 0; configurator.PrefetchCount = 1000; configurator.Handler<PingMessage>(async context => { if (Interlocked.Increment(ref count) == 100000) _completed.TrySetResult(count); }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _allDone = GetTask <int>(); Handler <RoutingSlipFaulted>(configurator, async context => { _completedRoutingSlips.Add(context.Message.TrackingNumber); int count = Interlocked.Increment(ref _count); if (count == _limit) { _allDone.TrySetResult(count); } }); }
/// <summary> /// For all configured messages type (handlers, consumers, and sagas), configures delayed redelivery using the retry configuration specified. /// Redelivery is configured once for each message type, and is added prior to the consumer factory or saga repository in the pipeline. /// </summary> /// <param name="configurator"></param> /// <param name="configureRetry"></param> public static void UseDelayedRedelivery(this IRabbitMqReceiveEndpointConfigurator configurator, Action <IRetryConfigurator> configureRetry) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (configureRetry == null) { throw new ArgumentNullException(nameof(configureRetry)); } var observer = new DelayedExchangeRedeliveryConfigurationObserver(configurator, configureRetry); }
/// <summary> /// Configures a Turnout on the receive endpoint, which executes a long-running job and supervises the job until it /// completes. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="configurator">The receive endpoint configurator</param> /// <param name="busFactoryConfigurator">The bus factory configuration to use a separate endpoint for the control traffic</param> /// <param name="configure"></param> public static void Turnout <T>(this IRabbitMqReceiveEndpointConfigurator configurator, IRabbitMqBusFactoryConfigurator busFactoryConfigurator, Action <ITurnoutHostConfigurator <T> > configure) where T : class { var temporaryQueueName = busFactoryConfigurator.GetTemporaryQueueName("turnout-"); busFactoryConfigurator.ReceiveEndpoint(configurator.Host, temporaryQueueName, turnoutEndpointConfigurator => { turnoutEndpointConfigurator.AutoDelete = true; turnoutEndpointConfigurator.Durable = false; configurator.ConfigureTurnoutEndpoints(busFactoryConfigurator, turnoutEndpointConfigurator, configure); }); }
protected override void ConfigureRabbitMqReceiveEndoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = GetTask <int>(); int count = 0; configurator.PrefetchCount = 1000; configurator.Handler <PingMessage>(async context => { if (Interlocked.Increment(ref count) == 100000) { _completed.TrySetResult(count); } }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.PrefetchCount = 100; configurator.Handler<PingMessage>(async context => { try { await context.RespondAsync(new PongMessage(context.Message.CorrelationId)); } catch (Exception ex) { Console.WriteLine(ex); } }); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.PrefetchCount = 100; configurator.Handler <PingMessage>(async context => { try { await context.RespondAsync(new PongMessage(context.Message.CorrelationId)); } catch (Exception ex) { Console.WriteLine(ex); } }); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _count = 0; _received = GetTask <ConsumeContext <PingMessage> >(); configurator.Handler <PingMessage>(async context => { if (_count++ < 2) { await context.Defer(TimeSpan.FromMilliseconds(2000)); return; } _received.TrySetResult(context); }); }
// For RabbitMQ private static void TuneForReportExecution(IRabbitMqReceiveEndpointConfigurator r) { // Queue should survive RabbitMQ restart r.Durable = true; // Queue should survive RSMassTransit restart r.AutoDelete = false; // RSMassTransit expects multiple service instances, competing for // infrequent, long-running requests. Prefetch optimizes for the // opposite case and actually *hinders* the spread of infrequent // messages across instances. Therefor, turn prefetch off here. r.PrefetchCount = 0; // Do transport-independent tuning TuneForReportExecution((IReceiveEndpointConfigurator)r); }
private void ConfigureSagaEndPoint(IRabbitMqReceiveEndpointConfigurator endpointConfigurator) { var stateMachine = new MySagaStateMachine(); try { var redisConnectionString = "192.168.99.100:6379"; var redis = ConnectionMultiplexer.Connect(redisConnectionString); ///If we switch to RedisSagaRepository and Consumer publish its response too quick, ///It seems like the consumer published event reached Saga instance before the state is updated ///When it happened, Saga will not process the response event because it is not in the "Processing" state //var repository = new RedisSagaRepository<SagaState>(() => redis.GetDatabase()); var repository = new InMemorySagaRepository <SagaState>(); endpointConfigurator.StateMachineSaga(stateMachine, repository); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.ConfigureConsumeTopology = false; _count = 0; _received = GetTask <ConsumeContext <PingMessage> >(); configurator.Handler <PingMessage>(async context => { if (_count++ == 0) { await context.Defer(TimeSpan.FromMilliseconds(100), (consumeContext, sendContext) => { _hit = true; }); return; } _received.TrySetResult(context); }); }
/// <summary> /// We may want to have a builder/endpoint context that could store things like management endpoint, etc. to configure /// filters and add configuration interfaces for things like concurrency limit and prefetch count /// </summary> /// <param name="configurator"></param> /// <param name="definition"></param> /// <param name="configure">The callback to invoke after the definition configuration has been applied</param> internal static void Apply(this IRabbitMqReceiveEndpointConfigurator configurator, IEndpointDefinition definition, Action <IRabbitMqReceiveEndpointConfigurator> configure = null) { if (definition.IsTemporary) { configurator.AutoDelete = true; configurator.Durable = false; } if (definition.PrefetchCount.HasValue) { configurator.PrefetchCount = (ushort)definition.PrefetchCount.Value; } if (definition.ConcurrentMessageLimit.HasValue) { var concurrentMessageLimit = definition.ConcurrentMessageLimit.Value; // if there is a prefetchCount, and it's greater than the concurrent message limit, we need a filter if (!definition.PrefetchCount.HasValue || definition.PrefetchCount.Value > concurrentMessageLimit) { configurator.UseConcurrencyLimit(concurrentMessageLimit); // we should determine a good value to use based upon the concurrent message limit if (definition.PrefetchCount.HasValue == false) { var calculatedPrefetchCount = concurrentMessageLimit * 12 / 10; configurator.PrefetchCount = (ushort)calculatedPrefetchCount; } } } definition.Configure(configurator); configure?.Invoke(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.Bind<PingMessage>(); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { Handler<Request>(configurator, x => x.RespondAsync(new Response())); }
protected override void ConfigureRabbitMqReceiveEndoint(IRabbitMqReceiveEndpointConfigurator configurator) { _ping = Handler <PingMessage>(configurator, async x => await x.RespondAsync(new PongMessage(x.Message.CorrelationId))); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _count = 0; configurator.Handler<PingMessage>(context => { Interlocked.Increment(ref _count); throw new IntentionalTestException(); }, x => x.UseDelayedRedelivery(r => r.Intervals(100, 200))); }
protected virtual void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _a = Handled <A>(configurator); _b = Handled <B>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _started = Handled<JobStarted>(configurator); _canceled = Handled<JobCanceled<ProcessFile>>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = Handled<RoutingSlipCompleted>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = Handled<RoutingSlipCompleted>(configurator); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); _firstActivityCompleted = Handled<RoutingSlipActivityCompleted>(configurator, context => context.Message.ActivityName.Equals(testActivity.Name)); _secondActivityCompleted = Handled<RoutingSlipActivityCompleted>(configurator, context => context.Message.ActivityName.Equals(secondActivity.Name)); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _first = Handler<FirstMessage>(configurator, async context => { await context.SchedulePublish(TimeSpan.FromSeconds(1), new SecondMessage()); }); _second = Handled<SecondMessage>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _allDone = GetTask<int>(); Handler<RoutingSlipFaulted>(configurator, async context => { _completedRoutingSlips.Add(context.Message.TrackingNumber); int count = Interlocked.Increment(ref _count); if (count == _limit) _allDone.TrySetResult(count); }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureInputQueueEndpoint(configurator); configurator.Handler<PingMessage>(context => context.RespondAsync(new PongMessage(context.Message.CorrelationId))); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { configurator.ConfigureConsumeTopology = false; _handler = Handled <IProxyMe>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _received = Handled<A>(configurator); _receivedB = Handled<B>(configurator); }
/// <summary> /// Configures the rabbit mq receive endpoint. /// </summary> /// <param name="configurator">The configurator.</param> protected virtual void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { this.OnConfigureRabbitMqReceiveEndoint?.Invoke(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _ping = Handler<PingMessage>(configurator, async x => { throw new InvalidOperationException("This is an expected test failure"); }); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _testConsumer = new TestConsumer(GetTask <A>(), GetTask <B>()); configurator.Consumer(() => _testConsumer); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureInputQueueEndpoint(configurator); _handled = Handled<PingMessage>(configurator); }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _repository = new InMemorySagaRepository <TestSaga>(); configurator.Saga(_repository); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _ping = Handler<PingMessage>(configurator, async x => await x.RespondAsync(new PongMessage(x.Message.CorrelationId))); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _completed = Handled<JobCompleted>(configurator, context => context.Message.GetArguments<ProcessFile>().Size == 1); _completed2 = Handled<JobCompleted>(configurator, context => context.Message.GetArguments<ProcessFile>().Size == 2); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { Handler<PingMessage>(configurator, context => { throw new SerializationException("This is fine, forcing death"); }); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _handled = Handled<A>(configurator); configurator.Bind(_boundExchange); }
public void ApplyPolicy(IRabbitMqReceiveEndpointConfigurator endpoint) { endpoint.AutoDelete = true; endpoint.Durable = false; }
protected override void ConfigureRabbitMqReceiveEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { base.ConfigureRabbitMqReceiveEndpoint(configurator); _receivedA = Handled <A>(configurator); }
protected override void ConfigureInputQueueEndpoint(IRabbitMqReceiveEndpointConfigurator configurator) { _handled = Handled<A>(configurator); configurator.Bind(BoundExchange, x => { x.Durable = false; x.AutoDelete = true; x.ExchangeType = ExchangeType.Direct; }); }