コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }