コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public ReusableTempWriter(ArrayPool <byte> bufferPool, ObjectPool <ReusableTempWriter> memStreamPool)
        {
            _memoryStream = new MemoryStreamSlim(bufferPool, AmqpPrimitivesWriter.BufferSize);

            _innerWriter = new InternalBigEndianWriter(_memoryStream);

            _writer2 = new AmqpPrimitivesWriter(_innerWriter, bufferPool, memStreamPool);
        }
コード例 #4
0
        public ReusableTempWriter(ArrayPool<byte> bufferPool, ObjectPool<ReusableTempWriter> memStreamPool)
        {
            _memoryStream = new MemoryStreamSlim(bufferPool, AmqpPrimitivesWriter.BufferSize);

            _innerWriter = new InternalBigEndianWriter(_memoryStream);

            _writer2 = new AmqpPrimitivesWriter(_innerWriter, bufferPool, memStreamPool);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
            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);
                }
            }
コード例 #8
0
        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);
            });
        }
コード例 #9
0
        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);
            });
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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);
            });
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
        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();
            }
        }
コード例 #17
0
        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);
        }
コード例 #18
0
		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();
		}
コード例 #19
0
 public void Write(AmqpPrimitivesWriter amqpWriter, ushort channel, ushort classId, ushort methodId, object optionalArg)
 {
     AmqpChannelLevelFrameWriter.InternalBasicNAck(amqpWriter, channel, classId, methodId, optionalArg);
 }
コード例 #20
0
 public static void WriteEmptyMethodFrame(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId)
 {
     writer.WriteFrameStart(AmqpConstants.FrameMethod, channel, 4, classId, methodId);
     writer.WriteOctet(AmqpConstants.FrameEnd);
 }
コード例 #21
0
 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);
 }
コード例 #22
0
 public static void ChannelCloseOk(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args)
 {
     AmqpConnectionFrameWriter.WriteEmptyMethodFrame(writer, channel, classId, methodId);
 }
コード例 #23
0
 public static void ChannelCloseOk(AmqpPrimitivesWriter writer, ushort channel, ushort classId, ushort methodId, object args)
 {
     AmqpConnectionFrameWriter.WriteEmptyMethodFrame(writer, channel, classId, methodId);
 }
コード例 #24
0
 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);
 }