Inheritance: Microsoft.Azure.Amqp.Framing.Attach
Exemple #1
0
        public static AmqpLinkSettings Create(Attach attach)
        {
            AmqpLinkSettings settings = new AmqpLinkSettings();
            settings.LinkName = attach.LinkName;
            settings.Role = !attach.Role.Value;
            settings.Source = attach.Source;
            settings.Target = attach.Target;
            settings.SndSettleMode = attach.SndSettleMode;
            settings.RcvSettleMode = attach.RcvSettleMode;
            settings.MaxMessageSize = attach.MaxMessageSize;
            settings.DesiredCapabilities = attach.DesiredCapabilities;
            settings.OfferedCapabilities = attach.OfferedCapabilities;
            settings.Properties = attach.Properties;
            if (settings.Role.Value)
            {
                settings.TotalLinkCredit = AmqpConstants.DefaultLinkCredit;
                settings.AutoSendFlow = true;
            }
            else
            {
                settings.InitialDeliveryCount = 0;
            }

            return settings;
        }
Exemple #2
0
        public DuplexAmqpLink(AmqpSession session, AmqpLinkSettings settings)
            : base("duplex")
        {
            AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Create, "Create");

            var senderSettings = new AmqpLinkSettings
            {
                Role = false,
                LinkName = settings.LinkName + ":out",
                SettleType = settings.SettleType,
                Source = new Source(),
                TotalLinkCredit = settings.TotalLinkCredit,
                AutoSendFlow = settings.AutoSendFlow,
                Target = settings.Target,
                Properties = settings.Properties
            };
            this.sender = new SendingAmqpLink(session, senderSettings);

            var receiverSettings = new AmqpLinkSettings
            {
                Role = true,
                LinkName = settings.LinkName + ":in",
                SettleType = settings.SettleType,
                Source = settings.Source,
                TotalLinkCredit = settings.TotalLinkCredit,
                AutoSendFlow = settings.AutoSendFlow,
                Target = new Target(),
                Properties = settings.Properties
            };
            this.receiver = new ReceivingAmqpLink(session, receiverSettings);
            this.receiver.SetTotalLinkCredit(receiverSettings.TotalLinkCredit, true); // WHY set both here AND on settings? Follow up with Xin.

            this.sender.SafeAddClosed(this.OnLinkClosed);
            this.receiver.SafeAddClosed(this.OnLinkClosed);
        }
        public async Task<SendingAmqpLink> CreateSendingLinkAsync(string path, TimeSpan timeout)
        {
            var timeoutHelper = new TimeoutHelper(timeout);

            AmqpSession session;
            if (!this.faultTolerantSession.TryGetOpenedObject(out session))
            {
                session = await this.faultTolerantSession.GetOrCreateAsync(timeoutHelper.RemainingTime());
            }

            var linkAddress = this.connectionString.BuildLinkAddress(path);

            var linkSettings = new AmqpLinkSettings()
            {
                Role = false,
                InitialDeliveryCount = 0,
                Target = new Target() { Address = linkAddress.AbsoluteUri },
                SndSettleMode = null, // SenderSettleMode.Unsettled (null as it is the default and to avoid bytes on the wire)
                RcvSettleMode = null, // (byte)ReceiverSettleMode.First (null as it is the default and to avoid bytes on the wire)
                LinkName = Guid.NewGuid().ToString("N") // Use a human readable link name to help with debugging
            };

            linkSettings.AddProperty(IotHubAmqpProperty.TimeoutName, timeoutHelper.RemainingTime().TotalMilliseconds);

            var link = new SendingAmqpLink(linkSettings);
            link.AttachTo(session);

            await OpenLinkAsync(link, timeoutHelper.RemainingTime());

            return link;
        }
        static AmqpLinkSettings SetLinkSettingsCommonProperties(AmqpLinkSettings linkSettings, TimeSpan timeSpan)
        {
            linkSettings.AddProperty(IotHubAmqpProperty.TimeoutName, timeSpan.TotalMilliseconds);
            linkSettings.AddProperty(IotHubAmqpProperty.ClientVersion, Utils.GetClientVersion());

            return linkSettings;
        }
        public async Task<RequestResponseAmqpLink> CreateRequestResponseLink(string path, TimeSpan timeout)
        {
            var timeoutHelper = new TimeoutHelper(timeout);

            AmqpSession session;
            if (!this.faultTolerantSession.TryGetOpenedObject(out session))
            {
                session = await this.faultTolerantSession.GetOrCreateAsync(timeoutHelper.RemainingTime());
            }

            var linkAddress = this.connectionString.BuildLinkAddress(path);

            var linkSettings = new AmqpLinkSettings()
            {
                TotalLinkCredit = 0,
                AutoSendFlow = false,
                Source = new Source() { Address = linkAddress.AbsoluteUri },
                SettleType = SettleMode.SettleOnDispose,
                LinkName = Guid.NewGuid().ToString("N") // Use a human readable link name to help with debuggin
            };

            SetLinkSettingsCommonProperties(linkSettings, timeoutHelper.RemainingTime());

            var link = new RequestResponseAmqpLink(session, linkSettings);

            await OpenLinkAsync(link, timeoutHelper.RemainingTime());

            return link;
        }
        public async Task<ReceivingAmqpLink> CreateReceivingLink(string path, TimeSpan timeout, uint prefetchCount)
        {
            var timeoutHelper = new TimeoutHelper(timeout);

            AmqpSession session;
            if (!this.faultTolerantSession.TryGetOpenedObject(out session))
            {
                session = await this.faultTolerantSession.GetOrCreateAsync(timeoutHelper.RemainingTime());
            }

            var linkAddress = this.connectionString.BuildLinkAddress(path);

            var linkSettings = new AmqpLinkSettings()
            {
                Role = true,
                TotalLinkCredit = prefetchCount,
                AutoSendFlow = prefetchCount > 0, 
                Source = new Source() { Address = linkAddress.AbsoluteUri },
                SndSettleMode = null, // SenderSettleMode.Unsettled (null as it is the default and to avoid bytes on the wire)
                RcvSettleMode = (byte)ReceiverSettleMode.Second, 
                LinkName = Guid.NewGuid().ToString("N") // Use a human readable link name to help with debuggin
            };

            SetLinkSettingsCommonProperties(linkSettings, timeoutHelper.RemainingTime());

            var link = new ReceivingAmqpLink(linkSettings);
            link.AttachTo(session);

            await OpenLinkAsync(link, timeoutHelper.RemainingTime());

            return link;
        }
Exemple #7
0
        public AmqpLink CreateLink(AmqpSession session, AmqpLinkSettings settings)
        {
            bool isReceiver = settings.Role.Value;
            AmqpLink link;
            if (isReceiver)
            {
                if (settings.Target is Target && ((Target)settings.Target).Dynamic())
                {
                    string name = string.Format("$dynamic.{0}", Interlocked.Increment(ref this.dynamicId));
                    this.queues.Add(name, new TestQueue(this));
                    ((Target)settings.Target).Address = name;
                }

                link = new ReceivingAmqpLink(session, settings);
            }
            else
            {
                if (((Source)settings.Source).Dynamic())
                {
                    string name = string.Format("$dynamic.{0}", Interlocked.Increment(ref this.dynamicId));
                    this.queues.Add(name, new TestQueue(this));
                    ((Source)settings.Source).Address = name;
                }

                link = new SendingAmqpLink(session, settings);
            }

            return link;
        }
Exemple #8
0
 public ErrorLink(AmqpSession session, AmqpLinkSettings settings)
     : base("error-link", session, settings)
 {
     settings.Properties = null;
 }
        protected static AmqpLinkSettings SetLinkSettingsCommonProperties(AmqpLinkSettings linkSettings, TimeSpan timeSpan)
        {
            linkSettings.AddProperty(IotHubAmqpProperty.TimeoutName, timeSpan.TotalMilliseconds);
#if WINDOWS_UWP
            // System.Reflection.Assembly.GetExecutingAssembly() does not exist for UWP, therefore use a hard-coded version name
            // (This string is picked up by the bump_version script, so don't change the line below)
            var UWPAssemblyVersion = "1.0.13";
            linkSettings.AddProperty(IotHubAmqpProperty.ClientVersion, UWPAssemblyVersion);
#else
            linkSettings.AddProperty(IotHubAmqpProperty.ClientVersion, Utils.GetClientVersion());
#endif

            return linkSettings;
        }
Exemple #10
0
            protected override IEnumerator <AsyncStep> GetAsyncSteps()
            {
                string address = CbsConstants.CbsAddress;

                while (this.RemainingTime() > TimeSpan.Zero)
                {
                    try
                    {
                        AmqpSessionSettings sessionSettings = new AmqpSessionSettings()
                        {
                            Properties = new Fields()
                        };
                        this.session = new AmqpSession(this.connection, sessionSettings, this);
                        connection.AddSession(session, null);
                    }
                    catch (InvalidOperationException exception)
                    {
                        this.Complete(exception);
                        yield break;
                    }

                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) => thisPtr.session.BeginOpen(t, c, s),
                                     (thisPtr, r) => thisPtr.session.EndOpen(r),
                                     ExceptionPolicy.Continue));

                    Exception lastException = this.LastAsyncStepException;
                    if (lastException != null)
                    {
                        AmqpTrace.Provider.AmqpOpenEntityFailed(this.connection, this.session, string.Empty, address, lastException.Message);
                        this.session.Abort();
                        this.Complete(lastException);
                        yield break;
                    }

                    AmqpLinkSettings settings = new AmqpLinkSettings();
                    settings.AddProperty(CbsConstants.TimeoutName, (uint)this.RemainingTime().TotalMilliseconds);
                    settings.Target = new Target()
                    {
                        Address = address
                    };
                    settings.Source = new Source()
                    {
                        Address = address
                    };
                    settings.InitialDeliveryCount = 0;
                    settings.TotalLinkCredit      = 50;
                    settings.AutoSendFlow         = true;
                    settings.SettleType           = SettleMode.SettleOnSend;

                    this.Link = new RequestResponseAmqpLink(this.session, settings);
                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) => thisPtr.Link.BeginOpen(t, c, s),
                                     (thisPtr, r) => thisPtr.Link.EndOpen(r),
                                     ExceptionPolicy.Continue));

                    lastException = this.LastAsyncStepException;
                    if (lastException != null)
                    {
                        AmqpTrace.Provider.AmqpOpenEntityFailed(this.connection, this.Link, this.Link.Name, address, lastException.Message);
                        this.session.SafeClose();
                        this.Link = null;
                        this.Complete(lastException);
                        yield break;
                    }

                    AmqpTrace.Provider.AmqpOpenEntitySucceeded(this.connection, this.Link, this.Link.Name, address);
                    yield break;
                }

                if (this.session != null)
                {
                    this.session.SafeClose();
                }

                this.Complete(new TimeoutException(AmqpResources.GetString(AmqpResources.AmqpTimeout, this.OriginalTimeout, address)));
            }
Exemple #11
0
 public ErrorLink(AmqpSession session, AmqpLinkSettings settings)
     : base("error-link", session, settings)
 {
     settings.Properties = null;
 }