private void OnTimer(object sender, ElapsedEventArgs args) { using (var wrapper = new RabbitMQWrapper()) { using (var authorRepo = new AuthorRepo()) { var authors = authorRepo.GetALL(); var json = JsonConvert.SerializeObject(authors); var byteData = Encoding.UTF8.GetBytes(json); wrapper.SendMessage(ConfigurationManager.AppSettings["RabbitMQExchange"], "Author", byteData); } using (var bookRepo = new BookRepo()) { var books = bookRepo.GetALL(); var json = JsonConvert.SerializeObject(books); var byteData = Encoding.UTF8.GetBytes(json); wrapper.SendMessage(ConfigurationManager.AppSettings["RabbitMQExchange"], "Book", byteData); } } }
public void SendToRabbitMQ(long id) { using (var bookRepo = Factory.GetService <IBookRepo>()) using (var sender = new RabbitMQWrapper()) { var model = bookRepo.Get(id); var list = new List <BookEM>(); list.Add(model); var json = JsonConvert.SerializeObject(list); var byteData = Encoding.UTF8.GetBytes(json); sender.SendMessage(ConfigurationManager.AppSettings["RabbitMQExchange"], "Book", byteData); } }