예제 #1
0
        public Task Publish(FlatDataPointDto flatDataPointDto)
        {
            var factory = new ConnectionFactory()
            {
                HostName = rabbitConfiguration.HostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var exchange   = "weather";
                    var routingKey = $"{flatDataPointDto.LocationName}.{flatDataPointDto.SensorId}";
                    var message    = JsonConvert.SerializeObject(flatDataPointDto);
                    var body       = Encoding.UTF8.GetBytes(message);

                    channel.ExchangeDeclare(exchange: exchange,
                                            type: "topic");

                    channel.BasicPublish(exchange: exchange,
                                         routingKey: routingKey,
                                         basicProperties: null,
                                         body: body);
                }
            return(Task.CompletedTask);
        }
예제 #2
0
 public async Task NewDataPointReceivedAsync(FlatDataPointDto dataPointDto)
 {
     await hubContext.Clients.All.SendAsync("ReceiveDataPoint", dataPointDto);
 }