コード例 #1
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator 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.UseScheduledRedelivery(Retry.Intervals(1000,2000)));
        }
コード例 #2
0
 protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     configurator.Handler<PingMessage>(async context =>
     {
         await context.RespondAsync(new PongMessage(context.Message.CorrelationId));
     });
 }
コード例 #3
0
 protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     configurator.Handler <PingMessage>(async context =>
     {
         await context.RespondAsync(new PongMessage(context.Message.CorrelationId));
     });
 }
コード例 #4
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler <ProcessDocument>(async context =>
            {
                if (!context.Message.StringData.HasValue)
                {
                    throw new ArgumentException("StringData was not present.");
                }

                var stringData = await context.Message.StringData.Value;
                if (string.IsNullOrWhiteSpace(stringData))
                {
                    throw new ArgumentException("StringData was empty.");
                }

                _stringDataAddress = context.Message.StringData.Address;
                _byteDataAddress   = context.Message.ByteData.Address;
                _streamDataAddress = context.Message.StreamData.Address;

                await context.RespondAsync <DocumentProcessed>(new
                {
                    context.Message.CorrelationId,
                    context.Message.StringData,
                    StringByteData = context.Message.StringData,
                    context.Message.ByteData,
                    context.Message.StringValue,
                    StringByteValue = context.Message.StringValue,
                    context.Message.ByteValue,
                    context.Message.StreamData
                });
            });
        }
コード例 #5
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator 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.UseScheduledRedelivery(Retry.Intervals(1000, 2000)));
        }
コード例 #6
0
 protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     configurator.Handler <PerformanceRequest>(async context =>
     {
         await context.RespondAsync(new PerformanceResultImpl(context.Message.Id));
     });
 }
コード例 #7
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator 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.Redeliver(TimeSpan.FromMilliseconds(1000));
                    return;
                }

                _timer.Stop();

                Console.WriteLine("{0} okay, now is good (retried {1} times)", DateTime.UtcNow,
                                  context.Headers.Get(MessageHeaders.RedeliveryCount, default(int?)));

                // okay, ready.
                _receivedTimeSpan = _timer.Elapsed;
                _received.TrySetResult(context);
            });
        }
コード例 #8
0
 protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     configurator.Handler <ComplexRequest>(async context =>
     {
         await context.RespondAsync <ComplexResponse>(new { });
     });
 }
コード例 #9
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler <SuperComplexRequest>(async context =>
            {
                Console.WriteLine(Encoding.UTF8.GetString(context.ReceiveContext.GetBody()));

                await context.RespondAsync <SuperComplexResponse>(new { });
            });
        }
コード例 #10
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler <JToken>(async context =>
            {
                await Console.Out.WriteLineAsync($"Received the token! {context.Message}");

                _completed.TrySetResult(context.Message);
            });
        }
コード例 #11
0
 protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     long value = 0;
     configurator.Handler<PingMessage>(async context =>
     {
         if (Interlocked.Increment(ref value) == 1000)
             _completed.TrySetResult(true);
     });
 }
コード例 #12
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            base.ConfigureInMemoryReceiveEndpoint(configurator);

        #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

            configurator.Handler <A>(async m =>
            {
                throw new System.Exception("Booom!");
            });

            configurator.Handler <Fault <A> >(async m =>
            {
                _faultTaskTcs.TrySetResult(m.Message);
            });

        #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        }
コード例 #13
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler<JToken>(async context =>
            {
                await Console.Out.WriteLineAsync($"Received the token! {context.Message}");

                _completed.TrySetResult(context.Message);
            });
        }
コード例 #14
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            base.ConfigureInputQueueEndpoint(configurator);

            #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

            configurator.Handler<A>(async m =>
            {
                throw new System.Exception("Booom!");
            });

            configurator.Handler<Fault<A>>(async m =>
            {
                _faultTaskTcs.TrySetResult(m.Message);
            });

            #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

        }
コード例 #15
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _count = 0;
            configurator.Handler<Interval>(async context =>
            {
                Interlocked.Increment(ref _count);
            });

            _done = Handled<Done>(configurator);
        }
コード例 #16
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            var sagaRepository = new InMemorySagaRepository<RegisterUserSaga>();
            configurator.Saga(sagaRepository);

            configurator.Handler<SendUserVerificationEmail>(async x =>
            {
                await Bus.Publish(new UserVerificationEmailSent(x.Message.CorrelationId, x.Message.Email));
            });
        }
コード例 #17
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            base.ConfigureInputQueueEndpoint(configurator);

            _received = Handled <IA>(configurator);

            _tweaked = GetTask <IA>();

            configurator.Handler <IA>(async context => _tweaked.TrySetResult(context.Message), x => x.UseTransform(t => t.Replace(p => p.Second, _ => "World")));
        }
コード例 #18
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _count = 0;
            configurator.Handler <Interval>(async context =>
            {
                Interlocked.Increment(ref _count);
            });

            _done = Handled <Done>(configurator);
        }
コード例 #19
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            var sagaRepository = new InMemorySagaRepository <RegisterUserSaga>();

            configurator.Saga(sagaRepository);

            configurator.Handler <SendUserVerificationEmail>(async x =>
            {
                await Bus.Publish(new UserVerificationEmailSent(x.Message.CorrelationId, x.Message.Email));
            });
        }
コード例 #20
0
ファイル: Batch_Specs.cs プロジェクト: orlando722/MassTransit
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _consumer = new FailingBatchConsumer();

            configurator.UseMessageRetry(r => r.Immediate(1));

            configurator.Consumer(() => _consumer);

            _task = GetTask <ConsumeContext <Fault <PingMessage> > >();
            configurator.Handler <Fault <PingMessage> >(async m => _task.SetResult(m));
        }
コード例 #21
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            long value = 0;

            configurator.Handler <PingMessage>(async context =>
            {
                if (Interlocked.Increment(ref value) == 1000)
                {
                    _completed.TrySetResult(true);
                }
            });
        }
コード例 #22
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _pingReceived     = GetTask <ConsumeContext <PingMessage> >();
            _scheduledMessage = GetTask <ScheduledMessage>();

            configurator.Handler <PingMessage>(async context =>
            {
                _pingReceived.TrySetResult(context);

                ScheduledMessage <PongMessage> scheduledMessage = await context.ScheduleSend(TimeSpan.FromSeconds(20), new PongMessage());

                _scheduledMessage.TrySetResult(scheduledMessage);

                throw new IntentionalTestException("This time bad things happen");
            });

            _pongReceived = GetTask <ConsumeContext <PongMessage> >();

            configurator.Handler <PongMessage>(async context =>
            {
                _pongReceived.TrySetResult(context);
            });
        }
コード例 #23
0
 protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     configurator.Handler <PingMessage>(async context =>
     {
         try
         {
             await context.RespondAsync(new PongMessage(context.Message.CorrelationId), Pipe.Execute <SendContext>(x => x.Serializer = null));
         }
         catch (Exception exception)
         {
             Console.WriteLine(exception);
         }
     });
 }
コード例 #24
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.UseInMemoryOutbox();

            _pingReceived = GetTask<ConsumeContext<PingMessage>>();

            configurator.Handler<PingMessage>(context =>
            {
                _pingReceived.TrySetResult(context);

                context.Respond(new PongMessage(context.Message.CorrelationId));

                throw new IntentionalTestException("This time bad things happen");
            });
        }
コード例 #25
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.UseInMemoryOutbox();

            _pingReceived = GetTask <ConsumeContext <PingMessage> >();

            configurator.Handler <PingMessage>(context =>
            {
                _pingReceived.TrySetResult(context);

                context.Respond(new PongMessage(context.Message.CorrelationId));

                throw new IntentionalTestException("This time bad things happen");
            });
        }
コード例 #26
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler <PingMessage>(async context =>
            {
            }, x =>
            {
                x.UseRateLimit(100, TimeSpan.FromSeconds(1));
                x.UseConcurrencyLimit(32);
            });

            _handled = Handled <PingMessage>(configurator);

            var consumer = new MultiTestConsumer(TestTimeout);

            consumer.Consume <PingMessage>();
            consumer.Consume <PongMessage>();

            consumer.Configure(configurator);
        }
コード例 #27
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler<PingMessage>(async context =>
            {
            }, x =>
            {
                x.UseRateLimit(100, TimeSpan.FromSeconds(1));
                x.UseConcurrencyLimit(32);
            });

            _handled = Handled<PingMessage>(configurator);

            var consumer = new MultiTestConsumer(TestTimeout);

            consumer.Consume<PingMessage>();
            consumer.Consume<PongMessage>();

            consumer.Configure(configurator);
        }
コード例 #28
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _completed = GetTask <ConsumeContext <DocumentProcessed> >();
            configurator.Handler <DocumentProcessed>(async context =>
            {
                if (!context.Message.StringData.HasValue)
                {
                    throw new ArgumentException("StringData was not present.");
                }

                var stringData = await context.Message.StringData.Value;
                if (string.IsNullOrWhiteSpace(stringData))
                {
                    throw new ArgumentException("StringData was empty.");
                }

                _completed.TrySetResult(context);
            });
        }
コード例 #29
0
ファイル: Batch_Specs.cs プロジェクト: orlando722/MassTransit
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _consumer = new FailingBatchConsumer();

            configurator.UseScheduledRedelivery(r => r.Intervals(100));
            configurator.UseMessageRetry(r => r.Immediate(1));

            configurator.Consumer(() => _consumer);

            configurator.Handler <Fault <PingMessage> >(async m =>
            {
                if (_firstId == m.Message.Message.CorrelationId)
                {
                    _firstFault.SetResult(m);
                }
                if (_secondId == m.Message.Message.CorrelationId)
                {
                    _secondFault.SetResult(m);
                }
            });
        }
コード例 #30
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _handled = GetTask <ConsumeContext <Documents> >();
            configurator.Handler <Documents>(async context =>
            {
                Assert.That(context.Message.Bodies, Is.Not.Null);
                Assert.That(context.Message.Bodies.Length, Is.EqualTo(2));

                Assert.That(context.Message.Bodies[0].Body, Is.Not.Null);
                Assert.That(context.Message.Bodies[0].Body.HasValue);

                byte[] bodyValue = await context.Message.Bodies[0].Body.Value;
                Assert.That(bodyValue, Is.Not.Null);
                Assert.That(bodyValue.Length, Is.EqualTo(10000));

                Assert.That(context.Message.Bodies[0].FileName, Is.Not.Null);
                Assert.That(context.Message.Bodies[0].FileName, Is.EqualTo("first.txt"));

                _handled.SetResult(context);
            });
        }
コード例 #31
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            configurator.Handler <ProcessPayload>(async context =>
            {
                if (!context.Message.Payload.HasValue)
                {
                    throw new ArgumentException("Payload was not present.");
                }

                var payload = await context.Message.Payload.Value;
                if (payload == null)
                {
                    throw new ArgumentException("Payload was null.");
                }

                _payloadAddress = context.Message.Payload.Address;

                await context.RespondAsync <PayloadProcessed>(new
                {
                    context.Message.Payload,
                });
            });
        }
コード例 #32
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _count    = 0;
            _received = new[]
            {
                GetTask <ConsumeContext <PingMessage> >(),
                GetTask <ConsumeContext <PingMessage> >(),
                GetTask <ConsumeContext <PingMessage> >(),
                GetTask <ConsumeContext <PingMessage> >()
            };
            _timestamps = new DateTime[4];

            configurator.UseScheduledRedelivery(r => r.Intervals(1000, 2000, 3000));

            configurator.Handler <PingMessage>(async context =>
            {
                _received[_count].TrySetResult(context);
                _timestamps[_count] = DateTime.Now;

                _count++;

                throw new IntentionalTestException("I'm so not ready for this jelly.");
            });
        }
コード例 #33
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            base.ConfigureInputQueueEndpoint(configurator);

            _received = Handled<IA>(configurator);

            _tweaked = GetTask<IA>();

            configurator.Handler<IA>(async context => _tweaked.TrySetResult(context.Message), x =>
            {
                x.UseTransform(t =>
                {
                    t.Set(p => p.Second, context => "World");
                });
            });
        }
コード例 #34
0
 protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     configurator.Handler<PerformanceRequest>(async context =>
     {
         await context.RespondAsync(new PerformanceResultImpl(context.Message.Id));
     });
 }
コード例 #35
0
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator 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.Redeliver(TimeSpan.FromMilliseconds(1000));
                    return;
                }

                _timer.Stop();

                Console.WriteLine("{0} okay, now is good (retried {1} times)", DateTime.UtcNow, context.Headers.Get(MessageHeaders.RedeliveryCount, default(int?)));

                // okay, ready.
                _receivedTimeSpan = _timer.Elapsed;
                _received.TrySetResult(context);
            });
        }