public void SubscribeMessages()
        {
            _messagesCollection = _connection.Observe("messages")
                                  .Where(m => m.Data?.Any() == true)
                                  .Select(m => Serialization.DeserializeMessage(Encoding.UTF8.GetString(m.Data)));

            _messagesCollection.Subscribe(message =>
            {
                message.RECEIPT_TIME = DateTime.Now;
                _testDbContext.MESSAGES.Add(message);
                _testDbContext.SaveChanges();
            });
        }
Esempio n. 2
0
        public void Run(IConnection connection)
        {
            string currentDirectoryPath = Directory.GetCurrentDirectory();
            string jsonPath             = Directory.GetParent(currentDirectoryPath) + "/config/config.json";
            var    config = new ConfigurationBuilder()
                            .SetBasePath(Directory.GetCurrentDirectory())
                            .AddJsonFile(jsonPath, optional: false)
                            .Build();

            INATSObservable <string> events = connection.Observe(config.GetValue <string>("NatsBus"))
                                              .Select(m => Encoding.Default.GetString(m.Data));

            events.Subscribe(id => TextRanker.CalculateRank(id, RedisDbContext.GetDesription(id)));
        }