Esempio n. 1
0
        public void SubscribeAndWait(int workTimeMillis = 85)
        {
            var factory = new DefaultWampChannelFactory();
            var binding = new JTokenMsgpackBinding();

            var channel = factory.CreateChannel("realm", new WebSocket4NetBinaryConnection <JToken>(Configs.ServerAddress, binding), binding);

            try
            {
                channel.Open().Wait();
                //
                for (var i = 0; i < Configs.N_SUBJECTS; i++)
                {
                    string topicUri = Configs.SUBJECT_ + i;
                    channel.RealmProxy.Services.GetSubject <WsEvent>(topicUri).Subscribe(
                        @event =>
                    {
                        Interlocked.Add(ref EventsConsumed, 1);
                        //
                        if (@event.Id % 100 == 0)
                        {
                            Logger.Info("Client #" + _id + ". Processing event #" + @event.Id);
                        }
                        //
                        Thread.Sleep(workTimeMillis);
                    },
                        ex =>
                    {
                        Logger.Error($"Error during {topicUri} subscription", ex);
                    });
                }
                //
                while (!_shouldTerminate())
                {
                    Thread.Sleep(1);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in Client #" + _id, ex);
                // ReSharper disable once LocalizableElement
                MessageBox.Show("Error in Client #" + _id + "\r\n\r\n" + ex, "Error");
                Application.Exit();
            }
            finally
            {
                channel.Close("Test complete", new GoodbyeDetails()
                {
                    Message = "Client #" + _id
                });
            }
        }
        public void Start()
        {
            _router = new WampHost();
            var jsonBinding = new JTokenJsonBinding();
            var msgPack     = new JTokenMsgpackBinding();

            _router.RegisterTransport(new FleckWebSocketTransport("ws://0.0.0.0:8080/ws"), jsonBinding, msgPack);
            _router.Open();

            var realm = _router.RealmContainer.GetRealmByName("com.weareadaptive.reactivetrader");

            realm.HostMetaApiService();
        }
Esempio n. 3
0
        public void SubscribeAndWait(int workTimeMillis = 85)
        {
            var factory = new DefaultWampChannelFactory();
            var binding = new JTokenMsgpackBinding();

            var channel = factory.CreateChannel("realm", new WebSocket4NetBinaryConnection<JToken>(Configs.ServerAddress, binding), binding);
            try
            {
                channel.Open().Wait();
                //
                for (var i = 0; i < Configs.N_SUBJECTS; i++)
                {
                    string topicUri = Configs.SUBJECT_ + i;
                    channel.RealmProxy.Services.GetSubject<WsEvent>(topicUri).Subscribe(
                        @event =>
                        {
                            Interlocked.Add(ref EventsConsumed, 1);
                            //
                            if (@event.Id%100 == 0)
                            {
                                Logger.Info("Client #" + _id + ". Processing event #" + @event.Id);
                            }
                            //
                            Thread.Sleep(workTimeMillis);
                        },
                        ex =>
                        {
                            Logger.Error($"Error during {topicUri} subscription", ex);
                        });
                }
                //
                while (!_shouldTerminate())
                {
                    Thread.Sleep(1);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in Client #" + _id, ex);
                // ReSharper disable once LocalizableElement
                MessageBox.Show("Error in Client #" + _id + "\r\n\r\n" + ex, "Error");
                Application.Exit();
            }
            finally
            {
                channel.Close("Test complete", new GoodbyeDetails()
                {
                    Message = "Client #" + _id
                });
            }
        }