コード例 #1
0
ファイル: TopicExchange.cs プロジェクト: 7256776/BaseNetFrame
        /// <summary>
        /// 发送到C队列
        /// </summary>
        /// <param name="mesg"></param>
        public void SendMQ(SendMessageDto dto)
        {
            string mesg      = "来自队列(" + dto.QueueName + ")" + dto.Message;
            var    sendBytes = Encoding.UTF8.GetBytes(mesg);

            //发布消息
            channel.BasicPublish(exchangeName, dto.QueueName, null, sendBytes);
        }
コード例 #2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="dto"></param>
        public void SendMQ(SendMessageDto dto)
        {
            string mesg = "来自队列(" + dto.QueueName + ")" + dto.Message;

            //创建连接会话对象
            using (IModel channel = connection.CreateModel())
            {
                channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
                //队列持久化
                //IBasicProperties properties = channel.CreateBasicProperties();
                //properties.Persistent = true;

                //消息内容
                byte[] body = Encoding.UTF8.GetBytes(mesg);
                //发送消息  routingKey设置接受队列的QueueName
                channel.BasicPublish(exchange: exchangeName, routingKey: dto.QueueName, basicProperties: null, body: body);
            }
        }
コード例 #3
0
ファイル: BaseExchange.cs プロジェクト: 7256776/BaseNetFrame
        public void SendMQ(SendMessageDto dto)
        {
            string mesg = "来自队列(" + dto.QueueName + ")" + dto.Message;

            //创建连接会话对象
            using (IModel channel = connection.CreateModel())
            {
                //消息内容
                byte[] body = Encoding.UTF8.GetBytes(mesg);

                //channel.BasicAcks += Channel_BasicAcks;
                //channel.BasicNacks += Channel_BasicNacks;
                //channel.BasicRecoverOk += Channel_BasicRecoverOk;
                //channel.BasicReturn += Channel_BasicReturn;
                //channel.CallbackException += Channel_CallbackException;
                //channel.FlowControl += Channel_FlowControl;
                //channel.ModelShutdown += Channel_ModelShutdown;

                //发送消息  routingKey设置接受队列的QueueName
                channel.BasicPublish(exchange: "", routingKey: dto.QueueName, basicProperties: null, body: body);
            }
        }