Beispiel #1
0
        public static void RunParallelReactiveConsumer(
            Original.IConnection conn,
            MyWorkerContext ctx,
            int agentCount
            )
        {
            var agentList = new List <ConsumingAgent>();

            try
            {
                Console.WriteLine($"Sub ({agentCount}) start {ctx.Subject}");
                ctx.CronoStart();

                var cde = new CountdownEvent(agentCount);
                for (int i = 0; i < agentCount; i++)
                {
                    var agent = ConsumingAgent.CreatePassive(conn, ctx, cde);
                    agentList.Add(agent);
                    ThreadPool.QueueUserWorkItem(agent.PassiveWorker);
                }
                cde.Wait();

                ctx.CronoStop();
                Console.WriteLine($"Sub ({agentCount}) end {ctx.Subject}");
            }
            finally
            {
                foreach (var agent in agentList)
                {
                    agent.Dispose();
                }
            }
        }
        public FlowmakerConnection(string natsServerUrl = null)
        {
            var factorty = new NC.ConnectionFactory();

            _natsOptions     = NC.ConnectionFactory.GetDefaultOptions();
            _natsOptions.Url = natsServerUrl == null ? "demo.nats.io:4222" : natsServerUrl;
            _connection      = factorty.CreateConnection(_natsOptions);
        }
        private void ProducingWorker(object state)
        {
            var ctx = (MyWorkerContext)state;

            Original.Options opts = ConnectionUtils.GetDefaultOptions();
            var cf = new Original.ConnectionFactory();

            using (Original.IConnection conn = cf.CreateConnection(opts))
            {
                Workers.RunPublisher(conn, ctx);
            }
        }
Beispiel #4
0
        public static ConsumingAgent CreateReactive(
            Original.IConnection conn,
            MyWorkerContext ctx,
            CountdownEvent cde
            )
        {
            var instance = new ConsumingAgent();

            instance._subReactive = conn.SubscribeAsync(ctx.Subject + ".>", instance.ReactiveHandler);
            instance._ctx         = ctx;
            instance._cde         = cde;
            return(instance);
        }
        private void ConsumingWorker(object state)
        {
            var ctx = (MyWorkerContext)state;

            Original.Options opts = ConnectionUtils.GetDefaultOptions();
            var cf = new Original.ConnectionFactory();

            using (Original.IConnection conn = cf.CreateConnection(opts))
            {
                Workers.RunParallelPassiveConsumer(conn, ctx, ConsumingAgentCount);
                //Workers.RunParallelReactiveConsumer(conn, ctx, ConsumingAgentCount);
            }
        }
Beispiel #6
0
        public static PublishingAgent Create(
            Original.IConnection conn,
            MyWorkerContext ctx,
            CountdownEvent cde
            )
        {
            var instance = new PublishingAgent();

            instance._conn   = conn;
            instance._ctx    = ctx;
            instance._cde    = cde;
            instance._buffer = new byte[1000 + (int)(ctx.Description.Length * 1.1)];
            return(instance);
        }
Beispiel #7
0
        public static void RunPublisher(
            Original.IConnection conn,
            MyWorkerContext ctx
            )
        {
            Console.WriteLine("Pub start " + ctx.Subject);
            ctx.CronoStart();

            var agent = PublishingAgent.Create(conn, ctx, null);

            agent.Worker(null);

            ctx.CronoStop();
            Console.WriteLine($"Pub end {ctx.FormatStats(1)}");
        }
Beispiel #8
0
    public void InitConnSetup(CfServerSetting setting, string roomKey)
    {
        Debug.Log(setting);
        GDServiceConfig = setting.GameDuelService;
        main_ch         = new Channel(
            setting.GameDuelService.Host, setting.GameDuelService.Port,
            ChannelCredentials.Insecure
            );

        GDSClient = new GameDuelService.GameDuelServiceClient(main_ch);

        var streamSet = setting.GameDuelService.StreamSetting;

        natOpt     = ConnectionFactory.GetDefaultOptions();
        natOpt.Url = $"{streamSet.Connector}://{streamSet.Host}:{streamSet.Port}";
        Debug.Log(natOpt.Url);
        RoomKey = roomKey;
        natConn = new ConnectionFactory().CreateConnection(natOpt);
        // natConn.SubscribeAsync($"ULZ.GDSvc/{RoomKey}", OnSubMsgHandle);
    }
Beispiel #9
0
 public FlowmakerChannel(IFlowmakerConnection flowmakerConnection, NC.IConnection connection, string subject)
 {
     _flowmakerConnection = flowmakerConnection;
     Connection           = connection;
     Subject = subject;
 }