/// <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); } }
protected IByteBuffer GetByteBuffer(IMicroMessage message) { var data = _messageEncoder.Encode(message); return(Unpooled.WrappedBuffer(data)); }
public byte[] Encode(IMicroMessage message) { var content = JsonConvert.SerializeObject(message); return(Encoding.UTF8.GetBytes(content)); }