internal static void InternalBasicPublish(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var basicPub = args as FrameParameters.BasicPublishArgs; // try { var userBuffer = basicPub.buffer; var properties = basicPub.properties; // First frame: Method uint payloadSize = (uint)(9 + basicPub.exchange.Length + basicPub.routingKey.Length); writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, payloadSize, classId, methodId); var w = writer; { w.WriteUShort(0); // reserved1 w.WriteShortstr(basicPub.exchange); w.WriteShortstr(basicPub.routingKey); w.WriteBits(basicPub.mandatory, false /* immediate*/); } writer.WriteOctet(AmqpConstants.FrameEnd); // First frame completed // Header frame (basic properties) WriteBasicPropertiesAsHeader(writer, channel, (ulong)userBuffer.Count, properties); // Header frame completed // what's the max frame size we can write? if (!writer.FrameMaxSize.HasValue) { throw new Exception("wtf? no frame max set!"); } // Frame body int maxSubFrameSize = (int)writer.FrameMaxSize.Value - EmptyFrameSize; // writer.FrameMaxSize == 0 ? buffer.Count : (int)writer.FrameMaxSize.Value - EmptyFrameSize; // write frames limited by the max size int written = 0; while (written < userBuffer.Count) { writer.WriteOctet(AmqpConstants.FrameBody); writer.WriteUShort(channel); var countToWrite = Math.Min(userBuffer.Count - written, maxSubFrameSize); writer.WriteLong((uint)countToWrite); // payload size writer.WriteRaw(userBuffer.Array, userBuffer.Offset + written, countToWrite); written += countToWrite; writer.WriteOctet(AmqpConstants.FrameEnd); } // Frame body completed } // finally { basicPub.Done(); } }
public static void WriteEmptyMethodFrame(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId) { const uint payloadSize = 4; writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, payloadSize, classId, methodId); writer.WriteOctet(AmqpConstants.FrameEnd); }
public ReusableTempWriter(ArrayPool <byte> bufferPool, ObjectPool <ReusableTempWriter> memStreamPool) { _memoryStream = new MemoryStreamSlim(bufferPool, AmqpPrimitivesWriter.BufferSize); _innerWriter = new InternalBigEndianWriter(_memoryStream); _writer2 = new AmqpPrimitivesWriter(_innerWriter, bufferPool, memStreamPool); }
public ReusableTempWriter(ArrayPool<byte> bufferPool, ObjectPool<ReusableTempWriter> memStreamPool) { _memoryStream = new MemoryStreamSlim(bufferPool, AmqpPrimitivesWriter.BufferSize); _innerWriter = new InternalBigEndianWriter(_memoryStream); _writer2 = new AmqpPrimitivesWriter(_innerWriter, bufferPool, memStreamPool); }
public static void ConnectionCloseOk(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { if (LogAdapter.ProtocolLevelLogEnabled) { LogAdapter.LogDebug(LogSource, "> ConnectionCloseOk"); } WriteEmptyMethodFrame(writer, channel, classId, methodId); }
internal static void InternalBasicNAck(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var b_args = args as FrameParameters.BasicNAckArgs; uint payloadSize = (uint)(8 + 5); writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, payloadSize, classId, methodId); // writer.WriteUShort(classId); // writer.WriteUShort(methodId); writer.WriteULong(b_args.deliveryTag); writer.WriteBits(b_args.multiple, b_args.requeue); writer.WriteOctet(AmqpConstants.FrameEnd); }
public void Write(AmqpPrimitivesWriter amqpWriter, ushort channel, ushort classId, ushort methodId, object optionalArg) { var @params = optionalArg as BasicPublishArgs; var maxFrameSize = amqpWriter.FrameMaxSize; if (@params.EstimatedSize >= (0.7 * maxFrameSize)) // estimated size >= 70% of max, then dont buffer it { AmqpChannelLevelFrameWriter.InternalBasicPublish(amqpWriter, channel, classId, methodId, optionalArg); } else { AmqpChannelLevelFrameWriter.InternalBufferedBasicPublish(amqpWriter, channel, classId, methodId, optionalArg); } }
public static void ChannelClose(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var closeArgs = (FrameParameters.CloseParams)args; writer.WriteFrameWithPayloadFirst(AmqpConstants.FrameMethod, channel, (w) => { w.WriteUShort(classId); w.WriteUShort(methodId); w.WriteUShort(closeArgs.replyCode); w.WriteShortstr(closeArgs.replyText); w.WriteUShort(classId); w.WriteUShort(methodId); }); }
public static void ChannelClose(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var closeArgs = (FrameParameters.CloseParams) args; writer.WriteFrameWithPayloadFirst(AmqpConstants.FrameMethod, channel, (w) => { w.WriteUShort(classId); w.WriteUShort(methodId); w.WriteUShort(closeArgs.replyCode); w.WriteShortstr(closeArgs.replyText); w.WriteUShort(classId); w.WriteUShort(methodId); }); }
internal static void InternalBufferedBasicPublish(AmqpPrimitivesWriter writerX, ushort channel, ushort classId, ushort methodId, object args) { var memStream = writerX._memStreamPool.GetObject(); try { InternalBasicPublish(memStream._writer2, channel, classId, methodId, args); writerX._writer.Write(memStream._memoryStream.InternalBuffer, 0, (int)memStream._memoryStream.Position); } finally { writerX._memStreamPool.PutObject(memStream); } }
internal static void InternalBasicNAck(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var b_args = args as FrameParameters.BasicNAckArgs; if (LogAdapter.ProtocolLevelLogEnabled) { LogAdapter.LogDebug(LogSource, "> BasicNAck : " + b_args.deliveryTag); } uint payloadSize = (uint)(8 + 5); writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, payloadSize, classId, methodId); writer.WriteULong(b_args.deliveryTag); writer.WriteBits(b_args.multiple, b_args.requeue); writer.WriteOctet(AmqpConstants.FrameEnd); }
private static void WriteBasicPropertiesAsHeader(AmqpPrimitivesWriter writer, ushort channel, ulong bodySize, BasicProperties properties) { if (properties.IsEmpty) { // short cut when it's empty uint payloadSize = 4 + 8 + 2; writer.WriteFrameStart(AmqpConstants.FrameHeader, channel, payloadSize, 60, 0); writer.WriteULong(bodySize); // no support for continuation. must be less than 15 bits used writer.WriteUShort(properties._presenceSWord); writer.WriteOctet(AmqpConstants.FrameEnd); } else { writer.WriteFrameHeader(channel, bodySize, properties); } }
public static void ConnectionClose(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var closeArgs = (FrameParameters.CloseParams)args; writer.WriteFrameWithPayloadFirst(AmqpConstants.FrameMethod, channel, (w) => { if (LogAdapter.ProtocolLevelLogEnabled) { LogAdapter.LogDebug(LogSource, "> ConnectionClose"); } w.WriteUShort(classId); w.WriteUShort(methodId); w.WriteUShort(closeArgs.replyCode); w.WriteShortstr(closeArgs.replyText); w.WriteUShort(classId); w.WriteUShort(methodId); }); }
internal static void InternalBasicPublish(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { var basicPub = args as FrameParameters.BasicPublishArgs; // try { var buffer = basicPub.buffer; var properties = basicPub.properties; // First frame: Method uint payloadSize = (uint) (9 + basicPub.exchange.Length + basicPub.routingKey.Length); writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, payloadSize, classId, methodId); var w = writer; { w.WriteUShort(0); // reserved1 w.WriteShortstr(basicPub.exchange); w.WriteShortstr(basicPub.routingKey); w.WriteBits(basicPub.mandatory, basicPub.immediate); } writer.WriteOctet(AmqpConstants.FrameEnd); // First frame completed // Header frame (basic properties) WriteBasicPropertiesAsHeader(writer, channel, (ulong)buffer.Count, properties); // Header frame completed // what's the max frame size we can write? if (!writer.FrameMaxSize.HasValue) throw new Exception("wtf? no frame max set!"); // Frame body var maxSubFrameSize = writer.FrameMaxSize == 0 ? (int)buffer.Count : (int)writer.FrameMaxSize.Value - EmptyFrameSize; // write frames limited by the max size int written = 0; while (written < buffer.Count) { writer.WriteOctet(AmqpConstants.FrameBody); writer.WriteUShort(channel); var countToWrite = Math.Min(buffer.Count - written, maxSubFrameSize); writer.WriteLong((uint)countToWrite); // payload size writer.WriteRaw(buffer.Array, buffer.Offset + written, countToWrite); written += countToWrite; writer.WriteOctet(AmqpConstants.FrameEnd); } // Frame body completed } // finally { basicPub.Done(); } }
internal async Task InternalDoConnectSocket(string hostname, int port) { var index = Interlocked.Increment(ref _counter); await _socketHolder.Connect(hostname, port, OnSocketClosed, index); _amqpWriter = new AmqpPrimitivesWriter(_socketHolder.Writer, null, null); _amqpReader = new AmqpPrimitivesReader(_socketHolder.Reader); _frameReader = new FrameReader(_socketHolder.Reader, _amqpReader, this); var t1 = new Thread(WriteFramesLoop) { IsBackground = true, Name = "WriteFramesLoop_" + index }; t1.Start(); var t2 = new Thread(ReadFramesLoop) { IsBackground = true, Name = "ReadFramesLoop_" + index }; t2.Start(); }
public void Write(AmqpPrimitivesWriter amqpWriter, ushort channel, ushort classId, ushort methodId, object optionalArg) { AmqpChannelLevelFrameWriter.InternalBasicNAck(amqpWriter, channel, classId, methodId, optionalArg); }
public static void WriteEmptyMethodFrame(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId) { writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, 4, classId, methodId); writer.WriteOctet(AmqpConstants.FrameEnd); }
public void Write(AmqpPrimitivesWriter amqpWriter, ushort channel, ushort classId, ushort methodId, object optionalArg) { // AmqpChannelLevelFrameWriter.InternalBasicPublish(amqpWriter, channel, classId, methodId, optionalArg); AmqpChannelLevelFrameWriter.InternalBufferedBasicPublish(amqpWriter, channel, classId, methodId, optionalArg); }
public static void ChannelCloseOk(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args) { AmqpConnectionFrameWriter.WriteEmptyMethodFrame(writer, channel, classId, methodId); }
public void Write(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object optionalArg) { writer.WriteFrameStart(AmqpConstants.FrameHeartbeat, 0, 0, null, null); writer.WriteOctet(AmqpConstants.FrameEnd); }