Exemplo n.º 1
0
        public static Amqp.Types.Map NMSMapToAmqp(IPrimitiveMap nmsmap)
        {
            if (nmsmap == null)
            {
                return(null);
            }
            Amqp.Types.Map result = new Amqp.Types.Map();
            if (nmsmap is Map.AMQP.AMQPValueMap)
            {
                return((nmsmap as Map.AMQP.AMQPValueMap).AmqpMap);
            }
            else
            {
                foreach (string key in nmsmap.Keys)
                {
                    object value = nmsmap[key];

                    if (value is IDictionary)
                    {
                        value = ConversionSupport.MapToAmqp(value as IDictionary);
                    }
                    else if (value is IList)
                    {
                        value = ConversionSupport.ListToAmqp(value as IList);
                    }

                    result[key] = value;
                    //Tracer.InfoFormat("Conversion key : {0}, value : {1}, valueType: {2} nmsValue: {3}, nmsValueType: {4}.",
                    //    key, value, value.GetType().Name, );
                }
            }
            return(result);
        }
        public static string ToString(Amqp.Types.Map map)
        {
            if (map == null)
            {
                return("{}");
            }
            string result = "{";
            bool   first  = true;

            foreach (object key in map.Keys)
            {
                if (first)
                {
                    result += "\n";
                }
                first = false;
                //
                // handle byte arrays for now
                // add more special handlers as needed.
                //
                if (map[key] is byte[])
                {
                    result += string.Format("key: {0}, len={1}, {2};\n", key.ToString(), (map[key] as byte[]).Length, BitConverter.ToString(map[key] as byte[]).Replace("-", " "));
                }
                else
                {
                    result += "key: " + key.ToString() + ", value: " + map[key].ToString() + ";\n";
                }
            }
            result += "}";
            return(result);
        }
Exemplo n.º 3
0
        public static IPrimitiveMap AmqpMapToNMS(Amqp.Types.Map map)
        {
            if (map == null)
            {
                return(null);
            }
            IPrimitiveMap result = new Map.AMQP.AMQPValueMap(map);

            return(result);
        }
Exemplo n.º 4
0
        public static IDictionary MapToNMS(Amqp.Types.Map map)
        {
            if (map == null)
            {
                return(null);
            }

            IDictionary dictionary = new Dictionary <object, object>(map) as IDictionary;

            return(dictionary);
        }
Exemplo n.º 5
0
        public static Amqp.Types.Map MapToAmqp(IDictionary dictionary)
        {
            if (dictionary == null)
            {
                return(null);
            }

            /*if (dictionary is Amqp.Types.Map)
             * {
             *  Amqp.Types.Map DictMap = dictionary as Amqp.Types.Map;
             *
             *  return DictMap.Clone() as Amqp.Types.Map;
             * }*/
            Amqp.Types.Map map      = new Amqp.Types.Map();
            IEnumerator    iterator = dictionary.Keys.GetEnumerator();

            iterator.MoveNext();
            object key = iterator.Current;

            if (key == null)
            {
                return(null);
            }
            object value = null;

            do
            {
                value = dictionary[key];
                if (value != null)
                {
                    Type valtype = value.GetType();
                    if (value is IDictionary)
                    {
                        map[key] = ConversionSupport.MapToAmqp(value as IDictionary);
                    }
                    else if (value is IList)
                    {
                        map[key] = ConversionSupport.ListToAmqp(value as IList);
                    }
                    else if (IsNMSType(value))
                    //else if (valtype.IsPrimitive || value is byte[] || value is String)
                    {
                        map[key] = value;
                    }
                    else
                    {
                        Tracer.InfoFormat("Failed to convert IDictionary[{0}], value{1} to Map value: Invalid Type: {2}",
                                          key, value.ToString(), valtype.Name);
                    }
                }
            }while (iterator.MoveNext() && (key = iterator.Current) != null);
            return(map);
        }
Exemplo n.º 6
0
        static void ReceiveMessages(string node, int count, string sessionId)
        {
            Trace.WriteLine(TraceLevel.Information, "Establishing a connection...");
            Address address = new Address(sbNamespace, 5671, keyName, keyValue);
            Connection connection = new Connection(address);

            Trace.WriteLine(TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            Trace.WriteLine(TraceLevel.Information, "Accepting a message session '{0}'...", sessionId ?? "<any>");
            Map filters = new Map();
            filters.Add(new Symbol("com.microsoft:session-filter"), sessionId);

            ReceiverLink receiver = new ReceiverLink(
                session,
                "sessionful-receiver-link",
                new Source() { Address = node, FilterSet = filters },
                null);

            for (int i = 0; i < count; i++)
            {
                Message message = receiver.Receive(30000);
                if (message == null)
                {
                    break;
                }

                if (i == 0)
                {
                    Trace.WriteLine(TraceLevel.Information, "Received message from session '{0}'", message.Properties.GroupId);
                }

                receiver.Accept(message);
            }

            Trace.WriteLine(TraceLevel.Information, "Finished receiving. Shutting down...");
            Trace.WriteLine(TraceLevel.Information, "");

            receiver.Close();
            session.Close();
            connection.Close();
        }
Exemplo n.º 7
0
        public static string ToString(Amqp.Types.Map map)
        {
            if (map == null)
            {
                return("{}");
            }
            string result = "{";
            bool   first  = true;

            foreach (object key in map.Keys)
            {
                if (first)
                {
                    result += "\n";
                }
                first   = false;
                result += "key: " + key.ToString() + ", value: " + map[key].ToString() + ";\n";
            }
            result += "}";
            return(result);
        }
Exemplo n.º 8
0
        // This function is the core receive function
        void ReceiveMessages(string scenario, int count, string filter, string partition,ReceivedData callback)
        {
            Trace.WriteLine(Amqp.TraceLevel.Information, "Running scenario '{0}', filter '{1}'...", scenario, filter);

            Trace.WriteLine(Amqp.TraceLevel.Information, "Establishing a connection...");
            Address address = new Address(sbNamespace, PORT, keyName, keyValue);
            Connection connection = new Connection(address);

            Trace.WriteLine(Amqp.TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            Trace.WriteLine(Amqp.TraceLevel.Information, "Creating a receiver link on partition {0}...", partition);
            string partitionAddress = entity + "/ConsumerGroups/$default/Partitions/" + partition;
            // Form the filter for receiving message based on the time stamp 
            Map filters = new Map();
            if (filter != null)
            {
                filters.Add(new Amqp.Types.Symbol("apache.org:selector-filter:string"),
                    new DescribedValue(new Amqp.Types.Symbol("apache.org:selector-filter:string"), filter));
            }

            string lastOffset = "-1";
            long lastSeqNumber = -1;
            DateTime lastEnqueueTime = DateTime.MinValue;

            ReceiverLink receiver = new ReceiverLink(
                session,
                "receiver-" + partition,
                new Source() { Address = partitionAddress, FilterSet = filters },
                null);
            // loop runs until clean up is called
            for (; g_bThreadActive; )
            {
                Message message = receiver.Receive(5000);
                if (message == null)
                {
                    continue;
                }

                receiver.Accept(message);
                Data data = (Data)message.BodySection;
                // Get the data such as offset, Seq number and Devicename from the response header
                lastOffset = (string)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-offset")];
                lastSeqNumber = (long)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-sequence-number")];
                lastEnqueueTime = (DateTime)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-enqueued-time")];
               
                var DeviceName = (string)message.MessageAnnotations[new Amqp.Types.Symbol("iothub-connection-device-id")];
                callback(data.Binary, DeviceName);
            }

            receiver.Close();
            session.Close();
            connection.Close();

        }
Exemplo n.º 9
0
        static Tuple<string, DateTime> ReceiveMessages(string scenario, int count, string filter, string partition)
        {
            Trace.WriteLine(TraceLevel.Information, "Running scenario '{0}', filter '{1}'...", scenario, filter);

            Trace.WriteLine(TraceLevel.Information, "Establishing a connection...");
            Address address = new Address(sbNamespace, 5671, keyName, keyValue);
            Connection connection = new Connection(address);

            Trace.WriteLine(TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            Trace.WriteLine(TraceLevel.Information, "Creating a receiver link on partition {0}...", partition);
            string partitionAddress = entity + "/ConsumerGroups/$default/Partitions/" + partition; ;
            Map filters = new Map();
            if (filter != null)
            {
                filters.Add(new Symbol("apache.org:selector-filter:string"),
                    new DescribedValue(new Symbol("apache.org:selector-filter:string"), filter));
            }

            string lastOffset = "-1";
            long lastSeqNumber = -1;
            DateTime lastEnqueueTime = DateTime.MinValue;

            ReceiverLink receiver = new ReceiverLink(
                session,
                "receiver-" + partition,
                new Source() { Address = partitionAddress, FilterSet = filters },
                null);

            int i;
            for (i = 0; i < count; i++)
            {
                Message message = receiver.Receive(30000);
                if (message == null)
                {
                    break;
                }

                receiver.Accept(message);
                lastOffset = (string)message.MessageAnnotations[new Symbol("x-opt-offset")];
                lastSeqNumber = (long)message.MessageAnnotations[new Symbol("x-opt-sequence-number")];
                lastEnqueueTime = (DateTime)message.MessageAnnotations[new Symbol("x-opt-enqueued-time")];
            }

            receiver.Close();
            Trace.WriteLine(TraceLevel.Information, "Received {0} messages on partition {1}", i, partition);
            Trace.WriteLine(TraceLevel.Information, "  offset: '{0}', sn: {1}, enqueue time: {2}", lastOffset, lastSeqNumber, lastEnqueueTime.ToString("hh:ss.fff"));
            Trace.WriteLine(TraceLevel.Information, "");

            session.Close();
            connection.Close();

            return Tuple.Create(lastOffset, lastEnqueueTime);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Writes a map value to a buffer.
        /// </summary>
        /// <param name="buffer">The buffer to write.</param>
        /// <param name="value">The map value.</param>
        /// <param name="smallEncoding">if true, try using small encoding if possible.</param>
        public static void WriteMap(ByteBuffer buffer, Map value, bool smallEncoding)
        {
            if (value == null)
            {
                AmqpBitConverter.WriteUByte(buffer, FormatCode.Null);
            }
            else
            {
                int pos = buffer.WritePos;
                AmqpBitConverter.WriteUByte(buffer, 0);
                AmqpBitConverter.WriteUInt(buffer, 0);
                AmqpBitConverter.WriteUInt(buffer, 0);

                foreach (var key in value.Keys)
                {
                    Encoder.WriteObject(buffer, key);
                    Encoder.WriteObject(buffer, value[key]);
                }

                int size = buffer.WritePos - pos - 9;
                int count = value.Count * 2;

                if (smallEncoding && size < byte.MaxValue && count <= byte.MaxValue)
                {
                    buffer.Buffer[pos] = FormatCode.Map8;
                    buffer.Buffer[pos + 1] = (byte)(size + 1);
                    buffer.Buffer[pos + 2] = (byte)count;
                    Array.Copy(buffer.Buffer, pos + 9, buffer.Buffer, pos + 3, size);
                    buffer.Shrink(6);
                }
                else
                {
                    buffer.Buffer[pos] = FormatCode.Map32;
                    AmqpBitConverter.WriteInt(buffer.Buffer, pos + 1, size + 4);
                    AmqpBitConverter.WriteInt(buffer.Buffer, pos + 5, count);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Reads a map value from a buffer.
        /// </summary>
        /// <param name="buffer">The buffer to read.</param>
        /// <param name="formatCode">The format code of the value.</param>
        public static Map ReadMap(ByteBuffer buffer, byte formatCode)
        {
            if (formatCode == FormatCode.Null)
            {
                return null;
            }

            int size;
            int count;
            if (formatCode == FormatCode.Map8)
            {
                size = AmqpBitConverter.ReadUByte(buffer);
                count = AmqpBitConverter.ReadUByte(buffer);
            }
            else if (formatCode == FormatCode.Map32)
            {
                size = (int)AmqpBitConverter.ReadUInt(buffer);
                count = (int)AmqpBitConverter.ReadUInt(buffer);
            }
            else
            {
                throw DecodeException(formatCode, buffer.Offset);
            }

            if (count % 2 > 0)
            {
                throw new AmqpException(ErrorCode.DecodeError,
                    Fx.Format(SRAmqp.InvalidMapCount, count));
            }

            Map value = new Map();
            for (int i = 0; i < count; i += 2)
            {
                value.Add(ReadObject(buffer), ReadObject(buffer));
            }

            return value;
        }
Exemplo n.º 12
0
        internal static void Initialize()
        {
            knownDescrided = new Map();

            serializers = new Serializer[]
            {
                // 0: null
                new Serializer()
                {
                    Type = null,
                    Encoder = delegate(ByteBuffer b, object o, bool s) { AmqpBitConverter.WriteUByte(b, FormatCode.Null); },
                    Decoder = delegate(ByteBuffer b, byte c) { return null; }
                },
                // 1: boolean
                new Serializer()
                {
                    Type = typeof(bool),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteBoolean(b, (bool)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadBoolean(b, c); }
                },
                // 2: ubyte
                new Serializer()
                {
                    Type = typeof(byte),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteUByte(b, (byte)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadUByte(b, c); }
                },
                // 3: ushort
                new Serializer()
                {
                    Type = typeof(ushort),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteUShort(b, (ushort)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadUShort(b, c); }
                },
                // 4: uint
                new Serializer()
                {
                    Type = typeof(uint),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteUInt(b, (uint)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadUInt(b, c); }
                },
                // 5: ulong
                new Serializer()
                {
                    Type = typeof(ulong),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteULong(b, (ulong)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadULong(b, c); }
                },
                // 6: byte
                new Serializer()
                {
                    Type = typeof(sbyte),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteByte(b, (sbyte)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadByte(b, c); }
                },
                // 7: short
                new Serializer()
                {
                    Type = typeof(short),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteShort(b, (short)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadShort(b, c); }
                },
                // 8: int
                new Serializer()
                {
                    Type = typeof(int),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteInt(b, (int)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadInt(b, c); }
                },
                // 9: long
                new Serializer()
                {
                    Type = typeof(long),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteLong(b, (long)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadLong(b, c); }
                },
                // 10: float
                new Serializer()
                {
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteFloat(b, (float)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadFloat(b, c); }
                },
                // 11: double
                new Serializer()
                {
                    Type = typeof(double),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteDouble(b, (double)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadDouble(b, c); }
                },
                // 12: char
                new Serializer()
                {
                    Type = typeof(char),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteChar(b, (char)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadChar(b, c); }
                },
                // 13: timestamp
                new Serializer()
                {
                    Type = typeof(DateTime),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteTimestamp(b, (DateTime)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadTimestamp(b, c); }
                },
                // 14: uuid
                new Serializer()
                {
                    Type = typeof(Guid),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteUuid(b, (Guid)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadUuid(b, c); }
                },
                // 15: binary
                new Serializer()
                {
                    Type = typeof(byte[]),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteBinary(b, (byte[])o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadBinary(b, c); }
                },
                // 16: string
                new Serializer()
                {
                    Type = typeof(string),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteString(b, (string)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadString(b, c); }
                },
                // 17: symbol
                new Serializer()
                {
                    Type = typeof(Symbol),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteSymbol(b, (Symbol)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadSymbol(b, c); }
                },
                // 18: list
                new Serializer()
                {
                    Type = typeof(List),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteList(b, (IList)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadList(b, c); }
                },
                // 19: map
                new Serializer()
                {
                    Type = typeof(Map),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteMap(b, (Map)o, s); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadMap(b, c); }
                },
                // 20: array
                new Serializer()
                {
                    Type = typeof(Array),
                    Encoder = delegate(ByteBuffer b, object o, bool s) { WriteArray(b, (Array)o); },
                    Decoder = delegate(ByteBuffer b, byte c) { return ReadArray(b, c); }
                },
                // 21: invalid
                null
            };

            codecByType = new Map()
            {
                { typeof(bool),     serializers[1] },
                { typeof(byte),     serializers[2] },
                { typeof(ushort),   serializers[3] },
                { typeof(uint),     serializers[4] },
                { typeof(ulong),    serializers[5] },
                { typeof(sbyte),    serializers[6] },
                { typeof(short),    serializers[7] },
                { typeof(int),      serializers[8] },
                { typeof(long),     serializers[9] },
                { typeof(float),    serializers[10] },
                { typeof(double),   serializers[11] },
                { typeof(char),     serializers[12] },
                { typeof(DateTime), serializers[13] },
                { typeof(Guid),     serializers[14] },
                { typeof(byte[]),   serializers[15] },
                { typeof(string),   serializers[16] },
                { typeof(Symbol),   serializers[17] },
                { typeof(List),     serializers[18] },
                { typeof(Map),      serializers[19] },
                { typeof(Fields),   serializers[19] },
            };

            codecIndexTable = new byte[][]
            {
                // 0x40:null, 0x41:boolean.true, 0x42:boolean.false, 0x43:uint0, 0x44:ulong0, 0x45:list0
                new byte[] { 0, 1, 1, 4, 5, 18 },

                // 0x50:ubyte, 0x51:byte, 0x52:small.uint, 0x53:small.ulong, 0x54:small.int, 0x55:small.long, 0x56:boolean
                new byte[] { 2, 6, 4, 5, 8, 9, 1 },

                // 0x60:ushort, 0x61:short
                new byte[] { 3, 7 },

                // 0x70:uint, 0x71:int, 0x72:float, 0x73:char, 0x74:decimal32
                new byte[] { 4, 8, 10, 12 },

                // 0x80:ulong, 0x81:long, 0x82:double, 0x83:timestamp, 0x84:decimal64
                new byte[] { 5, 9, 11, 13 },

                // 0x98:uuid
                new byte[] { 21, 21, 21, 21, 21, 21, 21, 21, 14 },

                // 0xa0:bin8, 0xa1:str8, 0xa3:sym8
                new byte[] { 15, 16, 21, 17 },

                // 0xb0:bin32, 0xb1:str32, 0xb3:sym32
                new byte[] { 15, 16, 21, 17 },

                // 0xc0:list8, 0xc1:map8
                new byte[] { 18, 19 },

                // 0xd0:list32, 0xd1:map32
                new byte[] { 18, 19 },

                // 0xe0:array8
                new byte[] { 20 },

                // 0xf0:array32
                new byte[] { 20 }
            };
        }
Exemplo n.º 13
0
        Message[] ReceiveMessages(string scenario, int count, string filter, string partition)
        {
            Trace.WriteLine(TraceLevel.Information, "Running scenario '{0}', filter '{1}'...", scenario, filter);

            Trace.WriteLine(TraceLevel.Information, "Establishing a connection...");
            Connection connection = new Connection(this.GetAddress());

            Trace.WriteLine(TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            Trace.WriteLine(TraceLevel.Information, "Creating a receiver link on partition {0}...", partition);
            string partitionAddress = this.Entity + "/ConsumerGroups/$default/Partitions/" + partition; ;
            Map filters = new Map();
            if (filter != null)
            {
                filters.Add(new Symbol("apache.org:selector-filter:string"),
                    new DescribedValue(new Symbol("apache.org:selector-filter:string"), filter));
            }

            ReceiverLink receiver = new ReceiverLink(
                session,
                "receiver-" + partition,
                new Source() { Address = partitionAddress, FilterSet = filters },
                null);

            Message[] messages = new Message[count];
            for (int i = 0; i < count; i++)
            {
                Message message = receiver.Receive(30000);
                if (message == null)
                {
                    break;
                }

                receiver.Accept(message);
                Trace.WriteLine(
                    TraceLevel.Information,
                    "Received a message. sn: {0}, offset: '{1}', enqueue time: {2}",
                    (long)message.MessageAnnotations[new Symbol("x-opt-sequence-number")],
                    (string)message.MessageAnnotations[new Symbol("x-opt-offset")],
                    (DateTime)message.MessageAnnotations[new Symbol("x-opt-enqueued-time")]);

                messages[i] = message;
            }

            receiver.Close();
            session.Close();
            connection.Close();

            return messages;
        }
Exemplo n.º 14
0
        public void TestMethod_ReceiveWithFilter()
        {
            string testName = "ReceiveWithFilter";
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);

            Message message = new Message("I can match a filter");
            message.Properties = new Properties() { GroupId = "abcdefg" };
            message.ApplicationProperties = new ApplicationProperties();
            message.ApplicationProperties["sn"] = 100;

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            sender.Send(message, null, null);

            // update the filter descriptor and expression according to the broker
            Map filters = new Map();
            // JMS selector filter: code = 0x0000468C00000004L, symbol="apache.org:selector-filter:string"
            filters.Add(new Symbol("f1"), new DescribedValue(new Symbol("apache.org:selector-filter:string"), "sn = 100"));
            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, new Source() { Address = testTarget.Path, FilterSet = filters }, null);
            Message message2 = receiver.Receive();
            receiver.Accept(message2);

            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
        }
Exemplo n.º 15
0
        protected Map BuildFilter(ReceiveLinkDescription receiveLink)
        {
            string filter = string.Empty;
            Map filters = null;

            if (receiveLink.SequenceCheckPoint > -1)
            {
                filter = string.Format(
                "amqp.annotation.x-opt-offset > {0}",
                receiveLink.SequenceCheckPoint);
            }
            else if (receiveLink.TimeCheckPoint > DateTime.MinValue)
            {
                // Get milliseconds since start of 1970
                long msOffset = (long)receiveLink.TimeCheckPoint.Subtract(
                    new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                filter = string.Format(
                    "amqp.annotation.x-opt-enqueuedtimeutc > {0}",
                    msOffset);
            }

            if (!string.IsNullOrWhiteSpace(filter))
            {
                filters = new Map();
                    filters.Add(new Symbol("apache.org:selector-filter:string"),
                        new DescribedValue(
                            new Symbol("apache.org:selector-filter:string"),
                            filter));
            }

            return filters;
        }
Exemplo n.º 16
0
 internal override void DecodeValue(ByteBuffer buffer)
 {
     this.map = Encoder.ReadMap(buffer, Encoder.ReadFormatCode(buffer));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes the described map object.
 /// </summary>
 /// <param name="descriptor">The descriptor of the concrete described map class.</param>
 /// <param name="keyType">The allowed key type.</param>
 protected DescribedMap(Descriptor descriptor, Type keyType)
     : base(descriptor)
 {
     this.keyType = keyType;
     this.map = new Map();
 }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            //Create host and register message processor
            var uri = new Uri(Address);
            var host = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo);
            host.RegisterMessageProcessor(MsgProcName, new MessageProcessor());
            host.Open();

            //Create client
            var connection = new Connection(new Address(Address));
            var session = new Session(connection);
            var sender = new SenderLink(session, "message-client", MsgProcName);

            //Send message with an object of the base class as the body
            var person = new Person() { EyeColor = "brown", Height = 175, Weight = 75 };
            SendMessage(sender, "Person", person);

            //Send message with an object of a derived class as the body
            var student = new Student()
            {
                GPA = 4.8,
                Address = new ListAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" }
            };
            SendMessage(sender, "Person", student);

            //Send message with an object of a derived class as the body
            var teacher = new Teacher()
            {
                Department = "Computer Science",
                Classes = new List<string>() { "CS101", "CS106", "CS210" }
            };
            SendMessage(sender, "Person", teacher);

            //Send message with nested simple map as the body
            var address = new InternationalAddress()
            {
                Address = new MapAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" },
                Country = "usa"
            };
            SendMessage(sender, "InternationalAddress", address);

            //Send message with an AMQP value (the described list form of a student) as the body
            var described = new DescribedValue(
                new Symbol("samples.amqpnetlite:student"),
                new List()
                {
                    80,
                    6,
                    "black",
                    4.9,
                    new DescribedValue(
                        new Symbol("PeerToPeer.CustomType.ListAddress"),
                        new List()
                        {
                            "123 Main St.",
                            "Big Apple",
                            "NY",
                            "12345"
                        }
                    )
                }
            );
            SendMessage(sender, "Person", described);

            //Send message with an AMQP value (simple map of an InternationalAddress) as the body
            var map = new Map()
            {
                { "street", "123 Main St." },
                { "city", "Big Apple" },
                { "state", "NY" },
                { "zip", "12345" }
            };
            SendMessage(sender, "MapAddress", map);

            //Send message with an AMQP value (simple map of an InternationalAddress) as the body
            var map2 = new Map()
            {
                { "address", new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } } },
                { "country", "usa" }
            };
            SendMessage(sender, "InternationalAddress", map2);

            sender.Close();
            session.Close();
            connection.Close();

            host.Close();
        }
Exemplo n.º 19
0
        internal override EventData ReceiveEventData()
        {
            if (this.factory.Open(this.entity))
            {
                if (this.session == null)
                {
                    this.session = new Session(this.factory.Connection);
                    // no offsets are set
                    if (((this.StartOffset == null) || (this.StartOffset == string.Empty)) && (this.ReceiverStartTime == DateTime.MaxValue))
                    {
                        this.link = new ReceiverLink(this.session, "amqp-receive-link " + this.entity, this.entity);
                    }
                    // existing offsets to set as filters
                    else
                    {
                        Map filters = new Map();

                        if ((this.StartOffset != null) && (this.StartOffset != string.Empty))
                        {
                            filters.Add(new Symbol("apache.org:selector-filter:string"),
                                        new DescribedValue(
                                            new Symbol("apache.org:selector-filter:string"),
                                            "amqp.annotation.x-opt-offset > '" + this.StartOffset + "'"));
                        }

                        if (this.ReceiverStartTime != DateTime.MaxValue)
                        {
                            string totalMilliseconds = ((long)(this.ReceiverStartTime.ToUniversalTime() - new DateTime(StartOfEpoch, DateTimeKind.Utc)).TotalMilliseconds()).ToString();

                            filters.Add(new Symbol("apache.org:selector-filter:string"),
                                        new DescribedValue(
                                            new Symbol("apache.org:selector-filter:string"),
                                            "amqp.annotation.x-opt-enqueuedtimeutc > " + totalMilliseconds + ""));
                        }

                        this.link = new ReceiverLink(this.session, "amqp-receive-link " + this.entity,
                                        new global::Amqp.Framing.Source()
                                        {
                                            Address = this.entity,
                                            FilterSet = filters
                                        }, null);
                    }
                }

                Message message = this.link.Receive();

                if (message != null)
                {
                    this.link.Accept(message);
                    return new EventData(message);
                }

                return null;
            }

            return null;
        }
Exemplo n.º 20
0
        Tuple<string, DateTime> ReceiveMessages(string scenario, int count, string filter, string partition)
        {
            Address address = new Address(sbNamespace, 5671, ReckeyName, ReckeyValue);
            Connection connection = new Connection(address);
            Session session = new Session(connection);
            string partitionAddress = entity + "/ConsumerGroups/$default/Partitions/" + partition; ;
            Map filters = new Map();
            if (filter != null)
            {
                filters.Add(new Amqp.Types.Symbol("apache.org:selector-filter:string"),
                    new DescribedValue(new Amqp.Types.Symbol("apache.org:selector-filter:string"), filter));
            }

            string lastOffset = "-1";
            long lastSeqNumber = -1;
            DateTime lastEnqueueTime = DateTime.MinValue;

            ReceiverLink receiver = new ReceiverLink(
                session,
                "receiver-" + partition,
                new Source() { Address = partitionAddress, FilterSet = filters },
                null);

            int i;
            for (i = 0; i < count; i++)
            {
                Message message = receiver.Receive(30000);
                if (message == null)
                {
                    break;
                }

                receiver.Accept(message);
                lastOffset = (string)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-offset")];
                lastSeqNumber = (long)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-sequence-number")];
                lastEnqueueTime = (DateTime)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-enqueued-time")];
            }

            receiver.Close();
            session.Close();
            connection.Close();
            return Tuple.Create(lastOffset, lastEnqueueTime);
        }
Exemplo n.º 21
0
 // this function is used to receive the feed back for the message sent
 private void ReceiveFeedback(ReceivedFeedBackData callback,string filter)
 {
     string audience = Fx.Format("{0}/messages/servicebound/feedback", HOST);
     string resourceUri = Fx.Format("{0}/messages/servicebound/feedback", HOST);
     string sasToken = GetSharedAccessSignature(SHARED_ACCESS_KEY_NAME, SHARED_ACCESS_KEY, resourceUri, new TimeSpan(1, 0, 0));
     bool cbs = PutCbsToken(connection, HOST, sasToken, audience);
     if (cbs)
     {
         string entity = "/messages/servicebound/feedback";
         // Form the filter for receiving message based on the time stamp 
         Map filters = new Map();
         if (filter != null)
         {
             filters.Add(new Amqp.Types.Symbol("apache.org:selector-filter:string"),
                 new DescribedValue(new Amqp.Types.Symbol("apache.org:selector-filter:string"), filter));
         }
         ReceiverLink receiveLink = new ReceiverLink(session, "receive-link", new Source() { Address = entity, FilterSet = filters },
         null);
         Message received = receiveLink.Receive();
         if (received != null)
         {
             receiveLink.Accept(received);
             Data data = (Data)received.BodySection;
             callback(Encoding.UTF8.GetString(data.Binary));
             Debug.WriteLine(Encoding.UTF8.GetString(data.Binary));
         }
         receiveLink.Close();
     }
    
 }
Exemplo n.º 22
0
 internal AMQPValueMap(Amqp.Types.Map map)
 {
     value = map;
 }
Exemplo n.º 23
0
        internal override EventData ReceiveEventData()
        {
            if (this.factory.OpenConnection())
            {
                if (this.session == null)
                {
                    this.session = new Session(this.factory.Connection);
                    if ((this.StartOffset == null) || (this.StartOffset == string.Empty))
                    {
                        this.link = new ReceiverLink(this.session, "amqp-receive-link " + this.Path, this.Path);
                    }
                    else
                    {
                        Map filters = new Map();
                        filters.Add(new Symbol("apache.org:selector-filter:string"),
                                    new DescribedValue(
                                        new Symbol("apache.org:selector-filter:string"),
                                        "amqp.annotation.x-opt-offset > '" + this.StartOffset + "'"));

                        this.link = new ReceiverLink(this.session, "amqp-receive-link " + this.Path,
                                        new global::Amqp.Framing.Source()
                                        {
                                            Address = this.Path,
                                            FilterSet = filters
                                        }, null);
                    }
                }

                Message message = this.link.Receive();

                if (message != null)
                {
                    this.link.Accept(message);
                    return new EventData(message);
                }

                return null;
            }

            return null;
        }