コード例 #1
0
ファイル: EventReceiver.cs プロジェクト: fredfourie/Argonaut
        public void InitializeChannels(ReceiveLinkDescription[] receiveLinks)
        {
            InitializeConnectionAndSession();

            foreach (var link in receiveLinks)
            {
                // Some sanity checks first
                if (link.Type != LinkType.Receive) continue;
                if (!this.partitions.Contains(link.PartitionId.ToString()))
                {
                    throw new Exception(string.Format(
                        "Partition '{0}' does not exist in this event hub and cannot be initialized.",
                        link.PartitionId));
                }

                string partitionAddress = string.Format(
                    "{0}/ConsumerGroups/{1}/Partitions/{2}",
                    this.settings.EventHubName,
                    link.ConsumerGroup,
                    link.PartitionId);

                var filters = BuildFilter(link);
                var amqpLink = new ReceiverLink(
                   this.amqpSession,
                   string.Format("receiver-{0}-{1}", this.Name, link.PartitionId),
                   new Source()
                   {
                       Address = partitionAddress,
                       FilterSet = filters
                   },
                   null);

                this.channels.Add(link.Name, new ReceiveChannel()
                {
                    Connection = amqpConnection,
                    Session = amqpSession,
                    Link = amqpLink,
                    Name = link.Name,
                    PartitionId = link.PartitionId.ToString()
                });
            }
        }
コード例 #2
0
ファイル: EventReceiver.cs プロジェクト: fredfourie/Argonaut
        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;
        }