public void Send(MessageViewModel model) { using (var connection = this.connectionFactory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "chatapp", durable: false, exclusive: false, autoDelete: false, arguments: null); var builder = new StringBuilder(); builder.Append(model.Ip); builder.Append(";"); builder.Append(model.Message); var data = Encoding.UTF8.GetBytes(builder.ToString()); channel.BasicPublish(exchange: "", routingKey: "chatapp", basicProperties: null, body: data); } } }
public IHttpActionResult Send(MessageViewModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model state"); } model.Ip = this.GetIp(); this.rabbitClient.Send(model); return this.Ok(); }
public IHttpActionResult Send(MessageViewModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model state"); } model.Ip = this.GetIp(); var builder = new StringBuilder(); builder.Append(model.Ip); builder.Append(";"); builder.Append(model.Message); this.pubNub.Publish(Channel, builder.ToString()); return this.Ok(); }