Task AcceptMessageAsync(IChannelHandlerContext context, PublishPacket publish) { Message message; try { var buffer = new byte[publish.Payload.ReadableBytes]; publish.Payload.GetBytes(0, buffer); var bodyStream = new MemoryStream(buffer); bodyStream.Position = 0; message = new Message(bodyStream); Util.PopulateMessagePropertiesFromPacket(message, publish); } catch (Exception ex) { ShutdownOnError(context, ex); return TaskConstants.Completed; } finally { publish.Release(); } this.onMessageReceived(message); return TaskConstants.Completed; }