コード例 #1
0
        protected virtual void Init()
        {
            var fabric = new ManualFabricBridge();

            mBridgeRequest  = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
            mBridgeResponse = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

            mWebApi = new UnityWebApiMicroservicePipeline("Web")
                      .CallOut(WebApiConfigure)
                      .AddChannelOutgoing("Request", "This is the outgoing request channel")
                      .AttachSender(mBridgeRequest.GetSender())
                      .Revert()
                      .AddChannelIncoming("Response", "This is the response channel back from the Service")
                      .AttachListener(mBridgeResponse.GetListener())
                      .Revert();


            mService1 = new MicroservicePipeline("Service")
                        .CallOut(ServiceConfigure)
                        .AddChannelIncoming("Request", "This is the incoming request channel from the API")
                        .AttachListener(mBridgeRequest.GetListener())
                        .Revert()
                        .AddChannelOutgoing("Response", "This is the outgoing request channel")
                        .AttachSender(mBridgeResponse.GetSender())
                        .Revert()
            ;


            mService1.Start();
            mWebApi.Start();
        }
コード例 #2
0
        protected virtual void Init()
        {
            var fabric    = new ManualFabricBridge();
            var bridgeOut = fabric[FabricMode.Queue];
            var bridgein  = fabric[FabricMode.Broadcast];

            mWebApi = new UnityWebApiMicroservicePipeline("Web")
                      .CallOut(WebApiConfigure)
                      .AddChannelOutgoing("Request", "This is the outgoing request channel")
                      .AttachSender(mBridgeRequest.GetSender())
                      .Revert()
                      .AddChannelIncoming("Response", "This is the response channel back from the Service")
                      .AttachListener(mBridgeResponse.GetListener())
                      .Revert();


            mService1 = new MicroservicePipeline("Service")
                        .CallOut(ServiceConfigure)
                        .AddChannelIncoming("Request", "This is the incoming request channel from the API")
                        .AttachListener(mBridgeRequest.GetListener())
                        .Revert()
                        .AddChannelOutgoing("Response", "This is the outgoing request channel")
                        .AttachSender(mBridgeResponse.GetSender())
                        .Revert()
            ;


            mService1.Start();
            mWebApi.Start();
        }
コード例 #3
0
        public void TestMethod1()
        {
            try
            {
                var fabric    = new ManualFabricBridge();
                var bridgeOut = fabric[FabricMode.Queue];
                var bridgein  = fabric[FabricMode.Broadcast];

                PersistenceClient <Guid, BridgeMe> init;
                DebugMemoryDataCollector           memp1, memp2;

                var p1 = new MicroservicePipeline("Sender")
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddDebugMemoryDataCollector(out memp1)
                         .AddChannelIncoming("cresponse")
                         .AttachListener(bridgein.GetListener())
                         .Revert()
                         .AddChannelOutgoing("crequest")
                         .AttachSender(bridgeOut.GetSender())
                         .AttachPersistenceClient("cresponse", out init)
                         .Revert()
                ;

                var p2 = new MicroservicePipeline("Receiver")
                         .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                         .AddDebugMemoryDataCollector(out memp2)
                         .AddChannelIncoming("crequest")
                         .AttachListener(bridgeOut.GetListener())
                         .AttachCommand(new PersistenceManagerHandlerMemory <Guid, BridgeMe>((e) => e.Id, (s) => new Guid(s)))
                         .Revert()
                         .AddChannelOutgoing("cresponse")
                         .AttachSender(bridgein.GetSender())
                ;

                p2.ToMicroservice().Events.ExecuteBegin += CommunicationBridgeTests_OnExecuteBegin;
                p1.Start();
                p2.Start();

                int check1 = p1.ToMicroservice().Commands.Count();
                int check2 = p2.ToMicroservice().Commands.Count();

                var entity = new BridgeMe()
                {
                    Message = "Momma"
                };
                var rs = init.Create(entity, new RepositorySettings()
                {
                    WaitTime = TimeSpan.FromMinutes(5)
                }).Result;
                var rs2 = init.Read(entity.Id).Result;

                Assert.IsTrue(rs2.IsSuccess);
                Assert.IsTrue(rs2.Entity.Message == "Momma");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #4
0
        public void TestReroute()
        {
            var                      bridgeOut = new ManualFabricBridge()[FabricMode.Queue];
            bool                     success = false;
            ManualResetEvent         mre = new ManualResetEvent(false);
            DebugMemoryDataCollector memp1, memp2;

            var p1 = new MicroservicePipeline("Sender")
                     .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                     .AddDebugMemoryDataCollector(out memp1)
                     .AddChannelIncoming("fredo")
                     .AttachCommand(typeof(IContractInitial), (ctx) =>
            {
                ctx.Responses.Add(new TransmissionPayload(ctx.Request.Message.Clone().SetDestination <IContractFinal>()));
                return(Task.FromResult(0));
            })
                     .Revert()
                     .AddChannelOutgoing("crequest")
                     .AttachSender(bridgeOut.GetSender())
                     .Revert()
            ;

            var p2 = new MicroservicePipeline("Receiver")
                     .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                     .AddDebugMemoryDataCollector(out memp2)
                     .AddChannelIncoming("crequest")
                     .AttachListener(bridgeOut.GetListener())
                     .AttachCommand(typeof(IContractFinal), (ctx) =>
            {
                var value = ctx.Request.Message.Holder.Object as string;

                success = value == "Hello";
                mre.Set();
                return(Task.FromResult(0));
            })
                     .Revert()
            ;

            p1.Start();
            p2.Start();

            //Send the message to the command asynchronously.
            p1.ToMicroservice().Dispatch.Process <IContractInitial>("Hello");

            mre.WaitOne();

            Assert.IsTrue(success);

            p1.Stop();
            p2.Stop();
        }
コード例 #5
0
        public void TestMethod1()
        {
            var fabric   = new ManualFabricBridge();
            var incoming = fabric[FabricMode.Queue];
            var response = fabric[FabricMode.Broadcast];

            ICommandInitiator init;

            var ms1 = new MicroservicePipeline("server")
                      .AdjustPolicyTaskManagerForDebug()
                      .AddChannelIncoming("freddy")
                      .AttachListener(incoming.GetListener())
                      .AttachCommand((ctx) => throw new Exception("All messed up"), ("one", "two"))
                      .Revert()
                      .AddChannelOutgoing("response")
                      .AttachSender(response.GetSender())
                      .Revert();

            var ms2 = new MicroservicePipeline("client")
                      .AdjustPolicyTaskManagerForDebug()
                      .AddChannelOutgoing("freddy")
                      .AttachSender(incoming.GetSender())
                      .Revert()
                      .AddChannelIncoming("response")
                      .AttachListener(response.GetListener())
                      .AttachICommandInitiator(out init)
                      .Revert()
            ;

            ms1.Start();
            ms2.Start();

            var rs = init.Process <string, string>(("freddy", "one", "two"), "hello").Result;

            Assert.IsTrue(rs.ResponseCode == 500);
        }
コード例 #6
0
        public void Redirect1()
        {
            try
            {
                var fabric    = new ManualFabricBridge();
                var bridgeOut = fabric[FabricMode.Queue];
                var bridgein  = fabric[FabricMode.Broadcast];

                ICommandInitiator        init;
                DebugMemoryDataCollector memp1, memp2;

                var client = new MicroservicePipeline("Sender")
                             .AdjustPolicyCommunicationBoundaryLoggingActive()
                             .AddDebugMemoryDataCollector(out memp1)
                             .AddChannelIncoming("cresponse", autosetPartition01: false)
                             .AttachPriorityPartition((0, 0.9M), (1, 1.1M))
                             .AttachListener(bridgein.GetListener())
                             .AttachICommandInitiator(out init)
                             .Revert()
                             .AddChannelOutgoing("crequest")
                             .AttachSender(bridgeOut.GetSender())
                ;

                var server = new MicroservicePipeline("Receiver")
                             .AdjustPolicyCommunicationBoundaryLoggingActive()
                             .AddDebugMemoryDataCollector(out memp2)
                             .AddChannelIncoming("credirect")
                             .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    ctx.ResponseSet(201, "Hi");
                    return(Task.FromResult(0));
                }, ("one", "two"))
                             .Revert()
                             .AddChannelIncoming("crequest")
                             .AttachMessageRedirectRule(
                    canRedirect: (p) => p.Message.MessageType.Equals("bridgeme", StringComparison.InvariantCultureIgnoreCase)
                    , redirect: (p) =>
                {
                    p.Message.MessageType = "BridgeMe2";
                    p.Message.ActionType  = "Whatever";
                }
                    )
                             .AttachMessageRedirectRule(
                    canRedirect: (p) => p.Message.MessageType.Equals("redirectme", StringComparison.InvariantCultureIgnoreCase)
                    , redirect: (p) =>
                {
                    p.Message.ChannelId   = "credirect";
                    p.Message.MessageType = "one";
                    p.Message.ActionType  = "two";
                }
                    )
                             .AttachListener(bridgeOut.GetListener())
                             .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    ctx.ResponseSet(400, "Blah");
                    return(Task.FromResult(0));
                }, ("BridgeMe", "create"))
                             .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    ctx.ResponseSet(200, "Yah!");
                    return(Task.FromResult(0));
                }, ("bridgeMe2", "whatever"))
                             .Revert()
                             .AddChannelOutgoing("cresponse")
                             .AttachSender(bridgein.GetSender())
                ;

                client.Start();
                server.Start();

                int check1 = client.ToMicroservice().Commands.Count();
                int check2 = server.ToMicroservice().Commands.Count();

                var entity = new BridgeMe()
                {
                    Message = "Momma"
                };

                var rs = init.Process <BridgeMe, string>(("crequest", "BRIDGEME", "create"), entity).Result;
                Assert.IsTrue(rs.ResponseCode == 200);

                var rs2 = init.Process <BridgeMe, string>(("crequest", "redirectme", "hmm"), entity).Result;
                Assert.IsTrue(rs2.ResponseCode == 201);

                client.Stop();
                server.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #7
0
        public void PipelineCaseInsensitive()
        {
            try
            {
                DebugMemoryDataCollector collector1, collector2;
                CommandInitiator         init = null;

                var fabric       = new ManualFabricBridge();
                var bridgeOut    = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                var bridgeReturn = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                var pClient = new MicroservicePipeline("Client");
                var pServer = new MicroservicePipeline("Server");

                pServer
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector2)
                .AddPayloadSerializerDefaultJson()
                .AddChannelIncoming("INTERNALIN", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition((0, 1.0M), (1, 0.9M))
                .AttachListener(bridgeOut.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("FRANKY", "johnny5"))
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(201, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "JoHnny6"))
                .Revert()
                .AddChannelOutgoing("return")
                .AttachSender(bridgeReturn.GetSender())
                .Revert();
                ;

                pClient
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1)
                .AddChannelIncoming("Return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;

                pClient.Start();
                pServer.Start();

                var list = new List <Task <ResponseWrapper <string> > >();

                list.Add(init.Process <ICaseSensitiveTest1, Blah, string>(new Blah()
                {
                    Message = "hello1"
                }));
                list.Add(init.Process <Blah, string>("Internalin", "franky", "johnny5", new Blah()
                {
                    Message = "hello2"
                }));
                list.Add(init.Process <Blah, string>(("InternalIn", "Franky", "johnny5"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("internalIN", "FRANKY", "johnny6"), new Blah()
                {
                    Message = "hello3"
                }));

                var result = Task.WhenAll(list).Result;

                result.ForEach((r) => Assert.IsTrue(r.ResponseCode == 200 || r.ResponseCode == 201));

                pClient.Stop();
                pServer.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
コード例 #8
0
        public void PersistenceClientServer()
        {
            try
            {
                var fabric         = new ManualFabricBridge();
                var bridgeRequest  = fabric[FabricMode.Queue];
                var bridgeResponse = fabric[FabricMode.Broadcast];

                PersistenceClient <Guid, Sample1> repo;

                var p1 = new MicroservicePipeline("Server")
                         .AddChannelIncoming("request")
                         .AttachPersistenceManagerHandlerMemory(
                    keyMaker: (Sample1 e) => e.Id
                    , keyDeserializer: (s) => new Guid(s)
                    , versionPolicy: ((e) => e.VersionId.ToString("N").ToUpperInvariant(), (e) => e.VersionId = Guid.NewGuid(), true)
                    )
                         .AttachListener(bridgeRequest.GetListener())
                         .Revert()
                         .AddChannelOutgoing("response")
                         .AttachSender(bridgeResponse.GetSender())
                ;

                var p2 = new MicroservicePipeline("Client")
                         .AddChannelIncoming("response")
                         .AttachListener(bridgeResponse.GetListener())
                         .Revert()
                         .AddChannelOutgoing("request")
                         .AttachSender(bridgeRequest.GetSender())
                         .AttachPersistenceClient("response", out repo)
                         .Revert()
                ;

                p1.Start();
                p2.Start();

                var sample = new Sample1()
                {
                    Message = "Hello mom"
                };
                var id = sample.Id;
                //Run a set of simple version entity tests.
                //Create
                Assert.IsTrue(repo.Create(sample).Result.IsSuccess);
                //Read
                var result = repo.Read(id).Result;
                Assert.IsTrue(result.IsSuccess);
                Assert.IsTrue(result.Entity.Message == "Hello mom");
                //Update success
                var rs = repo.Update(sample).Result;
                Assert.IsTrue(rs.IsSuccess);
                //We have enabled version policy and optimistic locking so the next command should fail.
                //Update fail as old version
                Assert.IsFalse(repo.Update(sample).Result.IsSuccess);
                //But this one should pass.
                //Update pass as new entity.
                Assert.IsTrue(repo.Update(rs.Entity).Result.IsSuccess);
                //Read
                Assert.IsTrue(repo.Read(sample.Id).Result.IsSuccess);
                //Delete
                Assert.IsTrue(repo.Delete(sample.Id).Result.IsSuccess);
                //Read fail.
                Assert.IsFalse(repo.Read(sample.Id).Result.IsSuccess);

                p1.Stop();
                p2.Stop();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #9
0
        public void MasterJobNegotiation()
        {
            var ctx = new EnqueueContext();

            var fabric       = new ManualFabricBridge();
            var bridgeOut    = fabric[FabricMode.Queue];
            var bridgeIn     = fabric[FabricMode.Broadcast];
            var bridgeMaster = fabric[FabricMode.Broadcast];

            try
            {
                PersistenceClient <Guid, BridgeMe> init1, init3;
                DebugMemoryDataCollector           memp1, memp2, memp3;
                ManualChannelSender incoming = null;

                var mast1 = new TestMasterJobCommand();
                var mast2 = new TestMasterJobCommand();
                var mast3 = new TestMasterJobCommand();

                ctx.Create("Sender1", bridgeOut, bridgeIn, bridgeMaster, mast1, out init1, out memp1);
                ctx.Create("Sender3", bridgeOut, bridgeIn, bridgeMaster, mast3, out init3, out memp3);

                ctx.Add("Receiver2"
                        , new MicroservicePipeline("Receiver2")
                        .AdjustPolicyTaskManagerForDebug()
                        .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                        .AddDebugMemoryDataCollector(out memp2)
                        .AddChannelIncoming("local", internalOnly: true)
                        .AttachCommand(mast2)
                        .Revert()
                        .AddChannelIncoming("crequest")
                        .AttachListener(bridgeOut.GetListener())
                        .AttachCommand(new PersistenceManagerHandlerMemory <Guid, BridgeMe>((e) => e.Id, (s) => new Guid(s)))
                        .Revert()
                        .AddChannelOutgoing("cresponse")
                        .AttachSender(bridgeIn.GetSender(), (a) => incoming = a as ManualChannelSender)
                        .Revert()
                        .AddChannelBroadcast("negotiate")
                        .AttachListener(bridgeMaster.GetListener())
                        .AttachSender(bridgeMaster.GetSender())
                        .AssignMasterJob(mast2)
                        .Revert()
                        //.AddChannelIncoming("Deadletter")
                        //    .AttachListener(incoming.GetDeadLetterListener())
                        //    .Revert()
                        , mast2);

                ctx.Services.Values.ForEach((v) => v.Start());

                //Check that the standard comms are working.
                var entity = new BridgeMe()
                {
                    Message = "Momma"
                };
                var rs = init1.Create(entity, new RepositorySettings()
                {
                    WaitTime = TimeSpan.FromSeconds(30)
                }).Result;
                var rs2 = init1.Read(entity.Id).Result;
                var rs3 = init3.Read(entity.Id).Result;
                Assert.IsTrue(rs2.IsSuccess);
                Assert.IsTrue(rs3.IsSuccess);
                Assert.IsTrue(rs2.Entity.Message == "Momma");

                //Wait for one of the services to go master.
                ctx.MasterJobSignal.WaitOne();
                //OK, next service take over
                Assert.IsNotNull(ctx.MasterName);
                ctx.MasterJobSignal.Reset();
                var holdme1 = ctx.MasterName;
                ctx.Stop(holdme1);

                //OK, final service take over
                ctx.MasterJobSignal.WaitOne();
                Assert.IsNotNull(ctx.MasterName);
                ctx.MasterJobSignal.Reset();
                var holdme2 = ctx.MasterName;
                ctx.Stop(holdme2);

                ctx.MasterJobSignal.WaitOne();
                var holdme3 = ctx.MasterName;
                ctx.Stop(ctx.MasterName);
                Assert.IsNotNull(holdme3);

                //Check that the payloads have been successfully signalled.
                Assert.IsTrue(bridgeOut.PayloadsAllSignalled);
                Assert.IsTrue(bridgeIn.PayloadsAllSignalled);
                //Assert.IsTrue(bridgeMaster.PayloadsAllSignalled);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #10
0
            public void TestMethod1()
            {
                try
                {
                    var fabric    = new ManualFabricBridge();
                    var bridgeOut = fabric[FabricMode.Queue];
                    var bridgein  = fabric[FabricMode.Broadcast];

                    var key = CreateSalt(128);

                    var encOut = new AesEncryptionHandler(key, keySize: 128);
                    var encIn  = new AesEncryptionHandler(key, keySize: 128);


                    PersistenceClient <Guid, SecureMe> init;
                    DebugMemoryDataCollector           memp1, memp2;

                    var p1 = new MicroservicePipeline("Sender")
                             .AddEncryptionHandler("rogue1", encOut)
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault   = true)
                             .AddDataCollector((c) => new DebugMemoryDataCollector(), (c) => memp1 = c)
                             .AddChannelIncoming("cresponse")
                             .AttachListener(bridgein.GetListener())
                             .Revert()
                             .AddChannelOutgoing("crequest")
                             .AttachTransportPayloadEncryption("rogue1")
                             .AttachSender(bridgeOut.GetSender())
                             .AttachPersistenceClient("cresponse", out init)
                             .Revert()
                    ;

                    var p2 = new MicroservicePipeline("Receiver")
                             .AddEncryptionHandler("rogue2", encIn)
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault   = true)
                             .AddDataCollector((c) => new DebugMemoryDataCollector(), (c) => memp2 = c)
                             .AddChannelIncoming("crequest")
                             .AttachTransportPayloadDecryption("rogue2")
                             .AttachListener(bridgeOut.GetListener())
                             .AttachCommand(new PersistenceManagerHandlerMemory <Guid, SecureMe>((e) => e.Id, (s) => new Guid(s)))
                             .Revert()
                             .AddChannelOutgoing("cresponse")
                             .AttachSender(bridgein.GetSender())
                    ;

                    p1.Start();
                    p2.Start();

                    int check1 = p1.ToMicroservice().Commands.Count();
                    int check2 = p2.ToMicroservice().Commands.Count();

                    var entity = new SecureMe()
                    {
                        Message = "Momma"
                    };
                    var rs = init.Create(entity, new RepositorySettings()
                    {
                        WaitTime = TimeSpan.FromMinutes(5)
                    }).Result;
                    var rs2 = init.Read(entity.Id).Result;

                    Assert.IsTrue(rs2.IsSuccess);
                    Assert.IsTrue(rs2.Entity.Message == "Momma");
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
コード例 #11
0
            public void TestMethod1()
            {
                try
                {
                    var fabric    = new ManualFabricBridge();
                    var bridgeOut = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                    var bridgein  = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                    PersistenceClient <Guid, SecureMe> init;
                    DebugMemoryDataCollector           memp1, memp2;

                    var p1 = new MicroservicePipeline("Sender")
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                             .AddAuthenticationHandlerJwtToken("id1", JwtHashAlgorithm.HS256, Encoding.UTF8.GetBytes("My big secret"))
                             .AddDebugMemoryDataCollector(out memp1)
                             .AddChannelIncoming("cresponse", boundaryLoggingEnabled: true)
                             .AttachListener(bridgein.GetListener())
                             .Revert()
                             .AddChannelOutgoing("crequest", boundaryLoggingEnabled: true)
                             .AttachSender(bridgeOut.GetSender())
                             .AttachTransportPayloadSignature("id1")
                             .AttachPersistenceClient("cresponse", out init)
                             .Revert()
                    ;

                    var p2 = new MicroservicePipeline("Receiver")
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                             .AddAuthenticationHandlerJwtToken("id1", JwtHashAlgorithm.HS256, Encoding.UTF8.GetBytes("My big secret"))
                             .AddDebugMemoryDataCollector(out memp2)
                             .AddChannelIncoming("crequest", boundaryLoggingEnabled: true)
                             .AttachListener(bridgeOut.GetListener())
                             .AttachTransportPayloadVerification("id1")
                             .AttachCommand(new PersistenceManagerHandlerMemory <Guid, SecureMe>((e) => e.Id, (s) => new Guid(s)))
                             .Revert()
                             .AddChannelOutgoing("cresponse", boundaryLoggingEnabled: true)
                             .AttachSender(bridgein.GetSender())
                             .Revert()
                    ;

                    p1.Start();
                    p2.Start();

                    int check1 = p1.ToMicroservice().Commands.Count();
                    int check2 = p2.ToMicroservice().Commands.Count();

                    var entity = new SecureMe()
                    {
                        Message = "Momma"
                    };
                    var rs = init.Create(entity, new RepositorySettings()
                    {
                        WaitTime = TimeSpan.FromSeconds(30)
                    }).Result;
                    var rs2 = init.Read(entity.Id).Result;

                    Assert.IsTrue(rs2.IsSuccess);
                    Assert.IsTrue(rs2.Entity.Message == "Momma");
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
コード例 #12
0
        public void Pipeline2()
        {
            try
            {
                DebugMemoryDataCollector collector1, collector1a, collector2;
                CommandInitiator         init  = null;
                CommandInitiator         init2 = null;

                IPipelineChannelIncoming <MicroservicePipeline> cpipeIn  = null;
                IPipelineChannelOutgoing <MicroservicePipeline> cpipeOut = null;

                var fabric       = new ManualFabricBridge();
                var bridgeOut    = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                var bridgeReturn = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                //bridgeReturn.Agent.OnReceive += (o, e) => { if (e.Payload.Extent.Days == 42) init.ToString(); };
                //bridgeReturn.Agent.OnException += (o, e) => { if (e.Payload.Extent.Days == 42) init.ToString(); };

                var pClient  = new MicroservicePipeline("Client");
                var pClient2 = new MicroservicePipeline("Client2");
                var pServer  = new MicroservicePipeline("Server");

                pServer
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector2)
                .AddPayloadSerializerDefaultJson()
                .AddChannelIncoming("internalIn", internalOnly: false
                                    , autosetPartition01: false
                                    , assign: (p, c) => cpipeIn = p)
                .AttachPriorityPartition((0, 1.0M), (1, 0.9M))
                .AttachListener(bridgeOut.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(201, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny6"))
                .Revert()
                .AddChannelOutgoing("return")
                .AttachSender(bridgeReturn.GetSender())
                .Revert();
                ;

                pClient
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1)
                .AddChannelIncoming("spooky", internalOnly: true)
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .Revert()
                .AddChannelIncoming("return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false
                                    , assign: (p, c) => cpipeOut = p)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;


                pClient2
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1a)
                .AddChannelIncoming("spooky", internalOnly: true)
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .Revert()
                .AddChannelIncoming("return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init2)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;

                pClient.Start();
                pClient2.Start();
                pServer.Start();

                init.OnRequestUnresolved  += Init_OnRequestUnresolved;
                init2.OnRequestUnresolved += Init_OnRequestUnresolved;

                var list = new List <Task <ResponseWrapper <string> > >();

                list.Add(init.Process <IPipelineTest2, Blah, string>(new Blah()
                {
                    Message = "hello1"
                }));
                list.Add(init.Process <Blah, string>("internalIn", "franky", "johnny5", new Blah()
                {
                    Message = "hello2"
                }));
                list.Add(init.Process <Blah, string>(("internalIn", "franky", "johnny5"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("internalIn", "franky", "johnny6"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("spooky", "franky", "johnny5"), new Blah()
                {
                    Message = "hellospooky"
                }));

                var result = Task.WhenAll(list).Result;

                result.ForEach((r) => Assert.IsTrue(r.ResponseCode == 200 || r.ResponseCode == 201));

                pClient.Stop();
                pClient2.Stop();
                pServer.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
コード例 #13
0
ファイル: ErrorPolicy.cs プロジェクト: rajeshcr/Microservice
        public void RPipeExternal()
        {
            PersistenceClient <Guid, PipeTest1> persistence, persistence2;
            CommandInitiator         init;
            DebugMemoryDataCollector collectorS, collectorC;

            var fabric       = new ManualFabricBridge();
            var bridgeOut    = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
            var bridgeReturn = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

            var server = new MicroservicePipeline($"{nameof(RPipeExternal)}server");
            var client = new MicroservicePipeline($"{nameof(RPipeExternal)}client");

            server.ToMicroservice().Events.ProcessRequestError += Events_ProcessRequestError;
            server.ToMicroservice().Events.ProcessRequestUnresolved += Events_ProcessRequestUnresolved;

            client.ToMicroservice().Events.ProcessRequestError += Events_ProcessRequestError;
            client.ToMicroservice().Events.ProcessRequestUnresolved += Events_ProcessRequestUnresolved;

            server
            .AdjustPolicyTaskManagerForDebug()
            .AddDebugMemoryDataCollector(out collectorS)
            .AddChannelIncoming("inChannel")
            .AttachPersistenceManagerHandlerMemory(
                (PipeTest1 e) => e.Id
                , (s) => new Guid(s)
                , resourceProfile: "Entity")
            .AttachListener(bridgeOut.GetListener())

            .Revert()
            .AddChannelOutgoing("return")
            .AttachSender(bridgeReturn.GetSender())
            .Revert()
            ;

            client
            .AdjustPolicyTaskManagerForDebug()
            .AddDebugMemoryDataCollector(out collectorC)
            .AddChannelIncoming("return")
            .AttachCommandInitiator(out init)
            .AttachListener(bridgeReturn.GetListener())
            .Revert()
            .AddChannelOutgoing("inChannel")
            .AttachPersistenceClient("return", out persistence)
            .AttachSender(bridgeOut.GetSender())
            .Revert()
            ;

            server.Start();
            client.Start();

            var result = persistence.Create(new PipeTest1()
            {
                Message = "Hello"
            }
                                            , new RepositorySettings()
            {
                WaitTime = TimeSpan.FromMinutes(5)
            }
                                            ).Result;

            Assert.IsTrue(result.ResponseCode == 201);

            //var result2 = persistence2.Create(new PipeTest1() { Message = "Hello" }
            //    , new RepositorySettings() { WaitTime = TimeSpan.FromSeconds(5) }
            //    ).Result;

            //Assert.IsTrue(result2.ResponseCode == 501);

            //var result3 = init.Process<string, string>(("franky", "four", "fingers"), ""
            //    , new RequestSettings { WaitTime = TimeSpan.FromSeconds(5) }, routing: ProcessOptions.RouteInternal
            //    ).Result;

            //Assert.IsTrue(result3.ResponseCode == 501);
        }