Exemple #1
0
        /// <summary> 发送消息 </summary>
        /// <param name="message">消息内容</param>
        /// <param name="flush">清空缓冲池</param>
        /// <returns>一个任务。</returns>
        public async Task Send(IMicroMessage message, bool flush = true)
        {
            var buffer = GetByteBuffer(message);

            if (flush)
            {
                await _context.WriteAndFlushAsync(buffer);
            }
            else
            {
                await _context.WriteAsync(buffer);
            }
        }
Exemple #2
0
        protected IByteBuffer GetByteBuffer(IMicroMessage message)
        {
            var data = _messageEncoder.Encode(message);

            return(Unpooled.WrappedBuffer(data));
        }
Exemple #3
0
        public byte[] Encode(IMicroMessage message)
        {
            var content = JsonConvert.SerializeObject(message);

            return(Encoding.UTF8.GetBytes(content));
        }