Esempio n. 1
0
        public MqttHandler(IConfiguration config, IHubContext <MessageHub> hubContext, IGamerContextMethods gamerStorage)
        {
            Id            = Guid.NewGuid();
            _config       = config;
            _hubContext   = hubContext;
            _gamerStorage = gamerStorage;
            var key = _config.GetValue <string>("MqttSettings:BrokerUri");

            _messageHandler = new MqttMessageHandler(key);
            _messageHandler.Subscribe(Topics.ScoreUpdate);
            _messageHandler.MqttMsgPublishReceived += _messageHandler_MqttMsgPublishReceived;
        }
Esempio n. 2
0
        private static void MqttTests()
        {
            var client = new MqttMessageHandler("tpg-hackathon.westeurope.cloudapp.azure.com");//new MqttMessageHandler("169.254.151.119");

            client.MqttMsgPublishReceived += PublishReceived;

            var gamerId = Guid.NewGuid();

            client.Subscribe(Topics.Gamer);

            var packmanPlayer = new Gamer()
            {
                Id = gamerId,
            };

            client.Publish <Gamer>(Topics.Gamer, packmanPlayer);

            client.Subscribe(Topics.Score);

            var score = new Score(gamerId, 1337);

            client.Publish <Score>(Topics.Score, score);
        }