private void button3_Click(object sender, EventArgs e) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.QueueDeclare("StartR", true, false, false, null); StartREntities db = new StartREntities(); var q = db.Clients.OrderBy(m => m.LastName).Take(10); foreach (var client in q) { QualifyClientCommand cmd = new QualifyClientCommand(); cmd.Address1 = client.Address1; cmd.Address2 = client.Address2; cmd.City = client.City; cmd.FirstName = client.FirstName; cmd.Id = client.Id; cmd.LastName = client.LastName; cmd.State = client.State; cmd.Zip = client.Zip; var ser = new XmlSerializer <QualifyClientCommand>(); var body = Encoding.UTF8.GetBytes(ser.Serialize(cmd)); channel.BasicPublish("", "StartR", null, body); } } toolStripStatusLabel1.Text = "Done sending clients."; } }
IMessageSender sender = new RabbitMQMessageSender(); //TODO: IOC public void Handle(ClientCreatedEvent msg, Action completion) { QualifyClientCommand cmd = new QualifyClientCommand(); cmd.Address1 = msg.Address1; cmd.Address2 = msg.Address2; cmd.City = msg.City; cmd.CreateDate = DateTime.Now; cmd.FirstName = msg.FirstName; cmd.Id = msg.Id; cmd.LastName = msg.LastName; cmd.State = msg.State; cmd.Zip = msg.Zip; sender.Send <QualifyClientCommand>(cmd); if (completion != null) { completion(); } }