Beispiel #1
0
        private void FindSession(FindSession findSession)
        {
            logger.Info("Find session (Id: {0})", findSession.SessionId);
            // Console.WriteLine("Find session (Id: {0})", findSession.SessionId);

            IActorRef sessionActor = Context.Child($"session-{ findSession.SessionId }");

            var sessionFound = new SessionFound(findSession.SessionId, sessionActor);

            Sender.Tell(sessionFound);
        }
Beispiel #2
0
        public async Task Post([FromBody] string value)
        {
            for (int index = 0; index < 10; index++)
            {
                string sessionId = $"{ index }";
                string userId    = $"{ index }";

                SessionFound sessionFound = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionFound>(new FindSession(sessionId), TimeSpan.FromSeconds(20));

                if (sessionFound.SessionActor.IsNobody())
                {
                    SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
                }

                // SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask<SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
            }
        }
Beispiel #3
0
        public async Task <IEnumerable <string> > Get()
        {
            for (int index = 0; index < 10; index++)
            {
                string sessionId = $"{ index }";
                string userId    = $"{ index }";

                SessionFound sessionFound = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionFound>(new FindSession(sessionId), TimeSpan.FromSeconds(2));

                if (sessionFound.SessionActor.IsNobody())
                {
                    SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(2));
                }

                // SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask<SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(2));
            }

            return(new string[] { "value1", "value2" });
        }
Beispiel #4
0
        public async Task SessionShouldBeDistributed()
        {
            IActorRef sessionRouterActor = ActorOf(Props.Create <SessionCollectionActor>().WithRouter(FromConfig.Instance), "session-router");

            for (int index = 0; index < 10; index++)
            {
                string sessionId = $"{ index }";
                string userId    = $"{ index }";

                SessionFound sessionFound = await sessionRouterActor.Ask <SessionFound>(new FindSession(sessionId), TimeSpan.FromSeconds(20));

                if (sessionFound.SessionActor.IsNobody())
                {
                    SessionCreated sessionCreated = await sessionRouterActor.Ask <SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
                }

                // SessionCreated sessionCreated = await sessionRouterActor.Ask<SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
            }
        }
Beispiel #5
0
        public void Start()
        {
            SalesOrderActorSystem.Start();

            ServicePointManager.DefaultConnectionLimit = 12;

            string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];

            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            if (!namespaceManager.QueueExists(queueName))
            {
                namespaceManager.CreateQueue(queueName);
            }

            queueClient = QueueClient.CreateFromConnectionString(connectionString, queueName);

            queueClient.OnMessageAsync(
                async message =>
            {
                try
                {
                    Console.WriteLine($"Processing: { message.SequenceNumber }, Label: { message.Label }...");

                    string sessionId = $"{ message.Properties["SessionId"] }";     // message.SessionId
                    string userId    = $"{ message.Properties["UserId"] }";

                    SessionFound sessionFound = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionFound>(new FindSession(sessionId), TimeSpan.FromSeconds(20));

                    if (sessionFound.SessionActor.IsNobody())
                    {
                        SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
                    }

                    // SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask<SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
                );
        }
Beispiel #6
0
        private async Task OnMessageAsync(BrokeredMessage message)
        {
            try
            {
                Trace.WriteLine($"Processing: { message.SequenceNumber }, Label: { message.Label }...");

                string sessionId = $"{ message.Properties["SessionId"] }"; // message.SessionId
                string userId    = $"{ message.Properties["UserId"] }";

                SessionFound sessionFound = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionFound>(new FindSession(sessionId), TimeSpan.FromSeconds(20));

                if (sessionFound.SessionActor.IsNobody())
                {
                    SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask <SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
                }

                // SessionCreated sessionCreated = await SalesOrderActorSystem.SessionRouterActor.Ask<SessionCreated>(new CreateSession(sessionId, userId), TimeSpan.FromSeconds(20));
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception);
            }
        }