public async Task Should_properly_use_the_original_specification_plus_more()
        {
            var specification = new SendPipeSpecification();

            specification.GetMessageSpecification <MyMessage>()
            .UseExecute(context => Console.WriteLine("Hello, World."));

            specification.GetMessageSpecification <IMyMessage>()
            .UseExecute(context =>
            {
            });

            var endpointSpecification = new SendPipeSpecification();

            endpointSpecification.ConnectSendPipeSpecificationObserver(new ParentSendPipeSpecificationObserver(specification));

            endpointSpecification.GetMessageSpecification <IMyMessage>()
            .UseConcurrencyLimit(1);

            endpointSpecification.GetMessageSpecification <ITraceableMessage>()
            .UsePartitioner(8, x => NewId.NextGuid());

            IPipe <SendContext <MyMessage> > pipe = endpointSpecification.GetMessageSpecification <MyMessage>().BuildMessagePipe();

            var sendContext = new InMemorySendContext <MyMessage>(new MyMessage());

            await pipe.Send(sendContext).ConfigureAwait(false);
        }
        public async Task Should_properly_use_the_original_specification_plus_topology_on_type()
        {
            var sendTopology = new SendTopology();

            sendTopology.GetMessageTopology <IMyMessage>()
            .Add(new TestMessageSendTopology <IMyMessage>());

            var specification = new SendPipeSpecification();

            specification.Connect(new TopologySendPipeSpecificationObserver(sendTopology));

            specification.GetMessageSpecification <MyMessage>()
            .UseConsoleLog(context => Task.FromResult("Hello, World."));

            specification.GetMessageSpecification <IMyMessage>()
            .UseExecute(context =>
            {
            });

            var endpointSpecification = new SendPipeSpecification();

            endpointSpecification.Connect(new ParentSendPipeSpecificationObserver(specification));

            endpointSpecification.GetMessageSpecification <IMyMessage>()
            .UseConcurrencyLimit(1);

            endpointSpecification.GetMessageSpecification <ITraceableMessage>()
            .UsePartitioner(8, x => NewId.NextGuid());

            IPipe <SendContext <MyMessage> > pipe = endpointSpecification.GetMessageSpecification <MyMessage>().BuildMessagePipe();

            var sendContext = new InMemorySendContext <MyMessage>(new MyMessage());

            await pipe.Send(sendContext).ConfigureAwait(false);
        }
Пример #3
0
        protected T SerializeAndReturn <T>(T obj)
            where T : class
        {
            byte[] serializedMessageData;

            using (var output = new MemoryStream())
            {
                var sendContext = new InMemorySendContext <T>(obj);

                sendContext.SourceAddress      = _sourceAddress;
                sendContext.DestinationAddress = _destinationAddress;
                sendContext.FaultAddress       = _faultAddress;
                sendContext.ResponseAddress    = _responseAddress;
                sendContext.RequestId          = _requestId;


                Serializer.Serialize(output, sendContext);

                serializedMessageData = output.ToArray();

                Trace.WriteLine(Encoding.UTF8.GetString(serializedMessageData));
            }

            return(Return <T>(serializedMessageData));
        }
Пример #4
0
        public void Just_how_fast_are_you()
        {
            var message = new SerializationTestMessage
            {
                DecimalValue  = 123.45m,
                LongValue     = 098123213,
                BoolValue     = true,
                ByteValue     = 127,
                IntValue      = 123,
                DateTimeValue = new DateTime(2008, 9, 8, 7, 6, 5, 4),
                TimeSpanValue = TimeSpan.FromSeconds(30),
                GuidValue     = Guid.NewGuid(),
                StringValue   = "Chris's Sample Code",
                DoubleValue   = 1823.172,
            };

            var            sendContext    = new InMemorySendContext <SerializationTestMessage>(message);
            ReceiveContext receiveContext = null;

            //warm it up
            for (int i = 0; i < 10; i++)
            {
                byte[] data = Serialize(sendContext);

                var transportMessage = new InMemoryTransportMessage(Guid.NewGuid(), data, Serializer.ContentType.MediaType, TypeMetadataCache <SerializationTestMessage> .ShortName);
                receiveContext = new InMemoryReceiveContext(new Uri("loopback://localhost/input_queue"), transportMessage, new ReceiveObservable(), null);

                Deserialize <SerializationTestMessage>(receiveContext);
            }

            Stopwatch timer = Stopwatch.StartNew();

            const int iterations = 50000;

            for (int i = 0; i < iterations; i++)
            {
                Serialize(sendContext);
            }

            timer.Stop();

            long perSecond = iterations * 1000 / timer.ElapsedMilliseconds;

            Console.WriteLine("Serialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond);


            timer = Stopwatch.StartNew();

            for (int i = 0; i < 50000; i++)
            {
                Deserialize <SerializationTestMessage>(receiveContext);
            }

            timer.Stop();

            perSecond = iterations * 1000 / timer.ElapsedMilliseconds;

            Console.WriteLine("Deserialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond);
        }
        public async Task Should_properly_delegate_the_specifications()
        {
            var specification = new SendPipeSpecification();

            specification.GetMessageSpecification <MyMessage>()
            .UseExecute(context => Console.WriteLine("Hello, World."));

            specification.GetMessageSpecification <IMyMessage>()
            .UseExecute(context =>
            {
            });

            IPipe <SendContext <MyMessage> > pipe = specification.GetMessageSpecification <MyMessage>().BuildMessagePipe();

            var sendContext = new InMemorySendContext <MyMessage>(new MyMessage());

            await pipe.Send(sendContext).ConfigureAwait(false);
        }
        public async Task Should_properly_use_the_original_specification()
        {
            var specification = new SendPipeSpecification();

            specification.GetMessageSpecification <MyMessage>()
            .UseConsoleLog(context => Task.FromResult("Hello, World."));

            specification.GetMessageSpecification <IMyMessage>()
            .UseExecute(context =>
            {
            });

            var endpointSpecification = new SendPipeSpecification();

            endpointSpecification.Connect(new ParentSendPipeSpecificationObserver(specification));

            IPipe <SendContext <MyMessage> > pipe = endpointSpecification.GetMessageSpecification <MyMessage>().BuildMessagePipe();

            var sendContext = new InMemorySendContext <MyMessage>(new MyMessage());

            await pipe.Send(sendContext).ConfigureAwait(false);
        }