Ejemplo n.º 1
0
 /// <summary>
 /// Initializes the object.
 /// </summary>
 /// <param name="session">The session where the link is created.</param>
 /// <param name="settings">The link settings.</param>
 public SendingAmqpLink(AmqpSession session, AmqpLinkSettings settings)
     : base("sender", session, settings)
 {
     // TODO: Add capability negotiation logic for BatchedMessageFormat to this.Settings
     this.pendingDeliveries   = new SerializedWorker <AmqpMessage>(this);
     this.inflightSends       = new WorkCollection <ArraySegment <byte>, SendAsyncResult, Outcome>(ByteArrayComparer.Instance);
     this.lastFlowRequestTime = DateTime.UtcNow;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the request response channel.
        /// </summary>
        /// <param name="type">A prefix of the object name for debugging purposes.</param>
        /// <param name="name">The object name.</param>
        /// <param name="session">The session in which the links are created.</param>
        /// <param name="address">The node address.</param>
        /// <param name="properties">The properties to send in attach performatives.</param>
        public RequestResponseAmqpLink(string type, string name, AmqpSession session, string address, Fields properties)
            : base(type)
        {
            this.Name    = name ?? string.Format(CultureInfo.InvariantCulture, "duplex{0}:{1}:{2}", session.Connection.Identifier, session.Identifier, this.Identifier);
            this.replyTo = Guid.NewGuid().ToString("N");

            try
            {
                AmqpLinkSettings senderSettings = new AmqpLinkSettings();
                senderSettings.Role       = false;
                senderSettings.LinkName   = this.Name + ":sender";
                senderSettings.SettleType = SettleMode.SettleOnSend;
                senderSettings.Source     = new Source();
                senderSettings.Target     = new Target()
                {
                    Address = address
                };
                senderSettings.Properties = properties;
                this.sender = new SendingAmqpLink(session, senderSettings);
                this.sender.SafeAddClosed(OnLinkClosed);

                AmqpLinkSettings receiverSettings = new AmqpLinkSettings();
                receiverSettings.Role       = true;
                receiverSettings.LinkName   = this.Name + ":receiver";
                receiverSettings.SettleType = SettleMode.SettleOnSend;
                receiverSettings.Source     = new Source()
                {
                    Address = address
                };
                receiverSettings.TotalLinkCredit = 50;
                receiverSettings.AutoSendFlow    = true;
                receiverSettings.Target          = new Target()
                {
                    Address = this.replyTo
                };
                if (properties != null)
                {
                    receiverSettings.Properties = new Fields();
                    receiverSettings.Properties.Merge(properties);
                }

                this.receiver = new ReceivingAmqpLink(session, receiverSettings);
                this.receiver.RegisterMessageListener(this.OnResponseMessage);
                this.receiver.SafeAddClosed(OnLinkClosed);
            }
            catch
            {
                this.sender?.SafeClose();
                this.receiver?.SafeClose();
                throw;
            }

            this.inflightRequests = new WorkCollection <MessageId, RequestAsyncResult, AmqpMessage>();
        }
Ejemplo n.º 3
0
        protected override bool OpenInternal()
        {
            this.messageQueue        = new SizeBasedFlowQueue(this);
            this.waiterList          = new LinkedList <ReceiveAsyncResult>();
            this.pendingDispositions = new WorkCollection <ArraySegment <byte>, DisposeAsyncResult, Outcome>(ByteArrayComparer.Instance);
            bool syncComplete = base.OpenInternal();

            if (this.LinkCredit > 0)
            {
                this.SendFlow(false);
            }

            return(syncComplete);
        }
Ejemplo n.º 4
0
        public RequestResponseAmqpLink(AmqpSession session, AmqpLinkSettings settings)
            : base("requestresponseamqplink")
        {
            this.Name    = string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", session.Connection.Identifier, session.Identifier, this.Identifier);
            this.replyTo = Guid.NewGuid().ToString("N");

            AmqpLinkSettings senderSettings = new AmqpLinkSettings();

            senderSettings.Role       = false;
            senderSettings.LinkName   = this.Name + ":sender";
            senderSettings.SettleType = settings.SettleType;
            senderSettings.Source     = new Source()
            {
                Address = Guid.NewGuid().ToString("N")
            };
            senderSettings.Target     = settings.Target;
            senderSettings.Properties = settings.Properties;
            this.sender         = new SendingAmqpLink(session, senderSettings);
            this.sender.Closed += new EventHandler(OnLinkClosed);

            AmqpLinkSettings receiverSettings = new AmqpLinkSettings();

            receiverSettings.Role                  = true;
            receiverSettings.LinkName              = this.Name + ":receiver";
            receiverSettings.SettleType            = settings.SettleType;
            receiverSettings.Source                = settings.Source;
            receiverSettings.TotalLinkCredit       = settings.TotalLinkCredit;
            receiverSettings.TotalCacheSizeInBytes = settings.TotalCacheSizeInBytes;
            receiverSettings.AutoSendFlow          = settings.AutoSendFlow;
            receiverSettings.Target                = new Target()
            {
                Address = this.replyTo
            };
            receiverSettings.Properties = settings.Properties;
            this.receiver = new ReceivingAmqpLink(session, receiverSettings);
            this.receiver.SetTotalLinkCredit(receiverSettings.TotalLinkCredit, applyNow: true);
            this.receiver.RegisterMessageListener(this.OnResponseMessage);
            this.receiver.Closed += new EventHandler(OnLinkClosed);

            this.inflightRequests = new WorkCollection <MessageId, RequestAsyncResult, AmqpMessage>();
        }