protected void OnAttachResponse(ILink sender, Attach attachResponse) { Tracer.InfoFormat("Attempting to close subscription {0}. Attach response {1}", this.Info.SubscriptionName, attachResponse); this.remoteSource = attachResponse.Source as Amqp.Framing.Source; if (this.remoteSource != null) { Tracer.InfoFormat("Found subscription {0} on remote with source {1}.", this.Info.SubscriptionName, this.remoteSource); this.OnResponse(); } }
/// <summary> /// Initializes a receiver link. /// </summary> /// <param name="session">The session within which to create the link.</param> /// <param name="name">The link name.</param> /// <param name="source">The source on attach that specifies the message source.</param> /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param> public ReceiverLink(Session session, string name, Source source, OnAttached onAttached) : this(session, name, new Attach() { Source = source, Target = new Target() }, onAttached) { }
/// <summary> /// Tests if this endpoint is capable of subscribing to and receiving message from the specified network address and AMQP source address. /// </summary> /// <param name="networkAddress">The network address of the target channel.</param> /// <param name="address">The AMQP source address from which messages will be received.</param> /// <param name="error">In the case of an error, returns information about the nature of the error.</param> /// <param name="virtualHostName">The name of the virtual host at the destination endpoint. Default is null for default virtual host. For RabbitMQ broker, use format vhost:MYVHOST</param> /// <param name="certificate">If secure amqps is being used, this property may optionally include the certificate that will be matched /// against the server's certificate. Leave null if you do not wish to perform certificate matching (secure communications will still be established /// using the server's certificate (if using amqps).</param> /// <returns>A boolean value indicated whether or not the channel is valid.</returns> public bool TestSubscribeChannel(Uri networkAddress, string address, out Exception error, string virtualHostName = null, X509Certificate certificate = null) { error = null; Connection conn = null; Session sess = null; ReceiverLink link = null; Exception ex = null; try { Open o = new Open() { ContainerId = Guid.NewGuid().ToString(), HostName = virtualHostName, MaxFrameSize = (uint)AmqpCFXEndpoint.MaxFrameSize.Value }; Amqp.Framing.Source source = new Amqp.Framing.Source() { Address = address, Durable = AmqpCFXEndpoint.DurableReceiverSetting.Value }; ConnectionFactory fact = new ConnectionFactory(); if (string.IsNullOrWhiteSpace(networkAddress.UserInfo)) { fact.SASL.Profile = SaslProfile.Anonymous; } if (networkAddress.Scheme.ToUpper() == "AMQPS") { LastCertificate = certificate; LastUri = networkAddress; fact.SSL.RemoteCertificateValidationCallback = ValidateServerCertificate; } Task <Connection> tConn = fact.CreateAsync(new Address(networkAddress.ToString()), o); tConn.Wait(3000); if (tConn.Status != TaskStatus.RanToCompletion) { throw new Exception("Timeout"); } conn = tConn.Result; conn.Closed += (IAmqpObject s, Error e) => { if (e != null) { ex = new Exception(e.Description); } }; sess = new Session(conn); sess.Closed += (IAmqpObject s, Error e) => { if (e != null) { ex = new Exception(e.Description); } }; if (ex != null) { throw ex; } link = new ReceiverLink(sess, address, source, null); link.Closed += (IAmqpObject s, Error e) => { if (e != null) { ex = new Exception(e.Description); } }; link.Close(); Task.Delay(10).Wait(); if (ex != null) { throw ex; } } catch (Exception ex2) { error = ex2; Debug.WriteLine(ex2.Message); } finally { if (sess != null && !sess.IsClosed) { sess.CloseAsync(); } if (conn != null && !conn.IsClosed) { conn.CloseAsync(); } } if (error == null) { return(true); } return(false); }