public void Publish(Message message, NetworkCredential credential) { try { var connectionFactory = new ConnectionFactory { HostName = credential.Domain, UserName = credential.UserName, Password = credential.Password, }; var conn = connectionFactory.CreateConnection(); var model = conn.CreateModel(); model.QueueDeclare(message.RoutingKey, true, false, false, null); using (conn) { using (model) { IBasicProperties props = model.CreateBasicProperties(); props.DeliveryMode = 2; model.BasicPublish("", message.RoutingKey, props, Encoding.UTF8.GetBytes(SerializeToJson(message))); } } } catch (Exception ex) { Console.WriteLine("Unable to connect to RabbitMQ"); } }
public override void HandleMessage(Message m) { var msg = (CommandMessage) m; Process p = new Process() { StartInfo = new ProcessStartInfo { CreateNoWindow = true, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = msg.WorkingDirectory, FileName = msg.ExecuteFile, Arguments = msg.Arguments, } }; p.OutputDataReceived += new DataReceivedEventHandler((o, e) => { Console.WriteLine(e.Data); if (OnOutputLineReady != null) OnOutputLineReady(msg.Ticket,e.Data); }); p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); }
public string SerializeToJson(Message msg) { var mem = new MemoryStream(256); _serializer.WriteObject(mem, msg); mem.Position = 0; var json = (new StreamReader(mem)).ReadToEnd(); return json; }
public virtual void HandleMessage(Message msg) { // default do nothing }