internal AmqpChannelFactory(AmqpTransportBindingElement bindingElement, BindingContext context) : base(context.Binding) { this.bindingElement = bindingElement; this.bindingContext = context; this.channelProperties = bindingElement.ChannelProperties.Clone(); this.shared = bindingElement.Shared; this.prefetchLimit = bindingElement.PrefetchLimit; this.maxBufferPoolSize = bindingElement.MaxBufferPoolSize; Collection <MessageEncodingBindingElement> messageEncoderBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>(); if (messageEncoderBindingElements.Count > 1) { throw new InvalidOperationException("More than one MessageEncodingBindingElement was found in the BindingParameters of the BindingContext"); } else if (messageEncoderBindingElements.Count == 1) { this.messageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory(); } else { this.messageEncoderFactory = new TextMessageEncodingBindingElement().CreateMessageEncoderFactory(); } openChannels = new List <AmqpTransportChannel>(); }
internal AmqpChannelListener(AmqpTransportBindingElement bindingElement, BindingContext context) : base(context.Binding) { this.bindingElement = bindingElement; this.channelProperties = bindingElement.ChannelProperties.Clone(); this.bindingContext = context; this.shared = bindingElement.Shared; this.prefetchLimit = bindingElement.PrefetchLimit; this.maxBufferPoolSize = bindingElement.MaxBufferPoolSize; // TODO: review this. Should be unique hostname based this.uri = context.ListenUriBaseAddress; this.asyncOnAcceptCaller = new AsyncOnAcceptCaller(this.OnAcceptChannel); this.acceptWaitEvent = new ManualResetEvent(false); Collection <MessageEncodingBindingElement> messageEncoderBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>(); if (messageEncoderBindingElements.Count > 1) { throw new InvalidOperationException("More than one MessageEncodingBindingElement was found in the BindingParameters of the BindingContext"); } else if (messageEncoderBindingElements.Count == 1) { this.messageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory(); } else { this.messageEncoderFactory = new TextMessageEncodingBindingElement().CreateMessageEncoderFactory(); } }
private static ManagedConnection GetManagedConnection(AmqpChannelProperties channelProperties, bool connectionSharing) { if (connectionSharing) { string key = MakeKey(channelProperties); lock (connectionLock) { ManagedConnection mc = null; if (!sharedInstances.TryGetValue(key, out mc)) { mc = new ManagedConnection(true); sharedInstances.Add(key, mc); } return mc; } } else { lock (connectionLock) { if (unsharedInstance == null) { unsharedInstance = new ManagedConnection(false); } return unsharedInstance; } } }
private static ManagedConnection GetManagedConnection(AmqpChannelProperties channelProperties, bool connectionSharing) { if (connectionSharing) { string key = MakeKey(channelProperties); lock (connectionLock) { ManagedConnection mc = null; if (!sharedInstances.TryGetValue(key, out mc)) { mc = new ManagedConnection(true); sharedInstances.Add(key, mc); } return(mc); } } else { lock (connectionLock) { if (unsharedInstance == null) { unsharedInstance = new ManagedConnection(false); } return(unsharedInstance); } } }
protected AmqpTransportBindingElement(AmqpTransportBindingElement other) : base(other) { this.channelProperties = other.channelProperties.Clone(); this.shared = other.shared; this.prefetchLimit = other.prefetchLimit; this.bindingSecurity = other.bindingSecurity; }
internal static void FindAuthenticationCredentials(AmqpChannelProperties channelProperties, BindingContext bindingContext) { AmqpTransportSecurity tsec = channelProperties.AmqpTransportSecurity; if (tsec == null) { // no auth return; } if (tsec.CredentialType == AmqpCredentialType.Anonymous) { // no auth return; } // credentials search order: specific AmqpCredentials, specific // ClientCredentials (if applicable), binding's default credentials AmqpCredential amqpCred = bindingContext.BindingParameters.Find <AmqpCredential>(); if (amqpCred != null) { channelProperties.AmqpCredential = amqpCred.Clone(); return; } if (!tsec.IgnoreEndpointClientCredentials) { ClientCredentials cliCred = bindingContext.BindingParameters.Find <ClientCredentials>(); if (cliCred != null) { if (cliCred.UserName != null) { if (cliCred.UserName.UserName != null) { channelProperties.AmqpCredential = new AmqpCredential(cliCred.UserName.UserName, cliCred.UserName.Password); return; } } } } if (tsec.DefaultCredential != null) { channelProperties.AmqpCredential = tsec.DefaultCredential.Clone(); } }
public AmqpChannelProperties Clone() { AmqpChannelProperties props = (AmqpChannelProperties)this.MemberwiseClone(); if (this.defaultMessageProperties != null) { props.defaultMessageProperties = this.defaultMessageProperties.Clone(); } if (this.amqpTransportSecurity != null) { props.amqpTransportSecurity = this.amqpTransportSecurity.Clone(); } if (this.amqpCredential != null) { this.amqpCredential = this.amqpCredential.Clone(); } return(props); }
private static string MakeKey(AmqpChannelProperties props) { StringBuilder sb = new StringBuilder(); sb.Append(props.BrokerHost); sb.Append(':'); sb.Append(props.BrokerPort); sb.Append(':'); sb.Append(props.TransferMode); AmqpTransportSecurity sec = props.AmqpTransportSecurity; if (sec == null) { return(sb.ToString()); } if (sec.UseSSL) { sb.Append(":SSL"); } if (sec.CredentialType == AmqpCredentialType.Plain) { sb.Append(":saslP"); AmqpCredential cred = props.AmqpCredential; if (cred != null) { sb.Append(":NM:"); sb.Append(cred.UserName); sb.Append(":PW:"); sb.Append(cred.Password); } } return(sb.ToString()); }
public static OutputLink GetOutputLink(AmqpChannelProperties channelProperties, bool connectionSharing, bool sessionSharing, string qname) { ManagedConnection mc = GetManagedConnection(channelProperties, connectionSharing); return (OutputLink)mc.GetLink(channelProperties, sessionSharing, null, qname); }
public object GetLink(AmqpChannelProperties channelProperties, bool sessionSharing, string inputQueue, string outputQueue) { AmqpConnection connection = null; AmqpSession session = null; Object link = null; bool newConnection = false; //bool newSession = false; bool success = false; // when called in the non-shared case, only stack variables should be used for holding connections/sessions/links if (this.shared) { Monitor.Enter(this); // lock } try { if (this.shared) { // TODO: check shared connection not closed (i.e. network drop) and refresh this instance if needed if (sessionSharing) { throw new NotImplementedException("shared session"); /* * ... once we have a defined shared session config parameter: // lazilly create if (this.sharedSessions == null) { this.sharedSessions = new Dictionary<string, AmqpSession>(); } alreadydeclaredstring sessionKey = channelProperties.name_of_key_goes_here; this.sharedSessions.TryGetValue(sessionKey, out session); * */ } if (this.sharedConnection != null) { connection = this.sharedConnection; } } if (connection == null) { if (channelProperties.AmqpSecurityMode != AmqpSecurityMode.None) { string user = null; string passwd = null; bool ssl = false; bool saslPlain = false; AmqpTransportSecurity tsec = channelProperties.AmqpTransportSecurity; if (tsec.UseSSL) { ssl = true; } if (tsec.CredentialType == AmqpCredentialType.Plain) { saslPlain = true; AmqpCredential plainCred = channelProperties.AmqpCredential; if (plainCred != null) { user = plainCred.UserName; passwd = plainCred.Password; } } connection = new AmqpConnection(channelProperties.BrokerHost, channelProperties.BrokerPort, ssl, saslPlain, user, passwd); } else { connection = new AmqpConnection(channelProperties.BrokerHost, channelProperties.BrokerPort); } newConnection = true; if (this.shared) { connection.OnConnectionIdle += new ConnectionIdleEventHandler(this.IdleConnectionHandler); } else { connection.OnConnectionIdle += new ConnectionIdleEventHandler(UnsharedIdleConnectionHandler); } } if (session == null) { session = connection.CreateSession(); //newSession = true; } if (inputQueue != null) { link = session.CreateInputLink(inputQueue); } else { link = session.CreateOutputLink(outputQueue); } if (this.shared) { if (newConnection) { this.sharedConnection = connection; } /* if (newSession) { sharedSessions.Add(foo, session); } * */ } success = true; } finally { if (this.shared) { Monitor.Exit(this); } if (!success) { /* if (newSession) { session.Close(); } */ if (newConnection) { connection.Close(); } } } return link; }
private static string MakeKey(AmqpChannelProperties props) { StringBuilder sb = new StringBuilder(); sb.Append(props.BrokerHost); sb.Append(':'); sb.Append(props.BrokerPort); sb.Append(':'); sb.Append(props.TransferMode); AmqpTransportSecurity sec = props.AmqpTransportSecurity; if (sec == null) { return sb.ToString(); } if (sec.UseSSL) { sb.Append(":SSL"); } if (sec.CredentialType == AmqpCredentialType.Plain) { sb.Append(":saslP"); AmqpCredential cred = props.AmqpCredential; if (cred != null) { sb.Append(":NM:"); sb.Append(cred.UserName); sb.Append(":PW:"); sb.Append(cred.Password); } } return sb.ToString(); }
internal AmqpTransportChannel(ChannelManagerBase factory, AmqpChannelProperties channelProperties, EndpointAddress remoteAddress, MessageEncoder msgEncoder, long maxBufferPoolSize, bool sharedConnection, int prefetchLimit) : base(factory) { this.isInputChannel = (factory is ChannelListenerBase) || (factory is AmqpChannelFactory <IInputChannel>); if (remoteAddress == null) { throw new ArgumentException("Null Endpoint Address"); } this.factoryChannelProperties = channelProperties; this.shared = sharedConnection; this.prefetchLimit = prefetchLimit; this.remoteAddress = remoteAddress; // pull out host, port, queue, and connection arguments string qpidAddress = this.UriToQpidAddress(remoteAddress.Uri, out subject); this.encoder = msgEncoder; string ct = String.Empty; if (this.encoder != null) { ct = this.encoder.ContentType; if (ct != null) { int pos = ct.IndexOf(';'); if (pos != -1) { ct = ct.Substring(0, pos).Trim(); } } else { ct = "application/octet-stream"; } } this.encoderContentType = ct; if (this.factoryChannelProperties.TransferMode == TransferMode.Streamed) { this.streamed = true; } else { if (!(this.factoryChannelProperties.TransferMode == TransferMode.Buffered)) { throw new ArgumentException("TransferMode mode must be \"Streamed\" or \"Buffered\""); } this.streamed = false; } this.bufferManager = BufferManager.CreateBufferManager(maxBufferPoolSize, int.MaxValue); this.asyncOpenCaller = new AsyncTimeSpanCaller(this.OnOpen); this.asyncCloseCaller = new AsyncTimeSpanCaller(this.OnClose); if (this.isInputChannel) { this.inputLink = ConnectionManager.GetInputLink(this.factoryChannelProperties, shared, false, qpidAddress); this.inputLink.PrefetchLimit = this.prefetchLimit; } else { this.outputLink = ConnectionManager.GetOutputLink(this.factoryChannelProperties, shared, false, qpidAddress); this.subject = this.outputLink.DefaultSubject; this.qpidSubject = this.outputLink.QpidSubject; } }
public object GetLink(AmqpChannelProperties channelProperties, bool sessionSharing, string inputQueue, string outputQueue) { AmqpConnection connection = null; AmqpSession session = null; Object link = null; bool newConnection = false; //bool newSession = false; bool success = false; // when called in the non-shared case, only stack variables should be used for holding connections/sessions/links if (this.shared) { Monitor.Enter(this); // lock } try { if (this.shared) { // TODO: check shared connection not closed (i.e. network drop) and refresh this instance if needed if (sessionSharing) { throw new NotImplementedException("shared session"); /* * ... once we have a defined shared session config parameter: * * // lazilly create * if (this.sharedSessions == null) * { * this.sharedSessions = new Dictionary<string, AmqpSession>(); * } * * alreadydeclaredstring sessionKey = channelProperties.name_of_key_goes_here; * this.sharedSessions.TryGetValue(sessionKey, out session); * * */ } if (this.sharedConnection != null) { connection = this.sharedConnection; } } if (connection == null) { if (channelProperties.AmqpSecurityMode != AmqpSecurityMode.None) { string user = null; string passwd = null; bool ssl = false; bool saslPlain = false; AmqpTransportSecurity tsec = channelProperties.AmqpTransportSecurity; if (tsec.UseSSL) { ssl = true; } if (tsec.CredentialType == AmqpCredentialType.Plain) { saslPlain = true; AmqpCredential plainCred = channelProperties.AmqpCredential; if (plainCred != null) { user = plainCred.UserName; passwd = plainCred.Password; } } connection = new AmqpConnection(channelProperties.BrokerHost, channelProperties.BrokerPort, ssl, saslPlain, user, passwd); } else { connection = new AmqpConnection(channelProperties.BrokerHost, channelProperties.BrokerPort); } newConnection = true; if (this.shared) { connection.OnConnectionIdle += new ConnectionIdleEventHandler(this.IdleConnectionHandler); } else { connection.OnConnectionIdle += new ConnectionIdleEventHandler(UnsharedIdleConnectionHandler); } } if (session == null) { session = connection.CreateSession(); //newSession = true; } if (inputQueue != null) { link = session.CreateInputLink(inputQueue); } else { link = session.CreateOutputLink(outputQueue); } if (this.shared) { if (newConnection) { this.sharedConnection = connection; } /* * if (newSession) * { * sharedSessions.Add(foo, session); * } * */ } success = true; } finally { if (this.shared) { Monitor.Exit(this); } if (!success) { /* * if (newSession) * { * session.Close(); * } */ if (newConnection) { connection.Close(); } } } return(link); }
public static InputLink GetInputLink(AmqpChannelProperties channelProperties, bool connectionSharing, bool sessionSharing, string qname) { ManagedConnection mc = GetManagedConnection(channelProperties, connectionSharing); return((InputLink)mc.GetLink(channelProperties, sessionSharing, qname, null)); }
internal static void FindAuthenticationCredentials(AmqpChannelProperties channelProperties, BindingContext bindingContext) { AmqpTransportSecurity tsec = channelProperties.AmqpTransportSecurity; if (tsec == null) { // no auth return; } if (tsec.CredentialType == AmqpCredentialType.Anonymous) { // no auth return; } // credentials search order: specific AmqpCredentials, specific // ClientCredentials (if applicable), binding's default credentials AmqpCredential amqpCred = bindingContext.BindingParameters.Find<AmqpCredential>(); if (amqpCred != null) { channelProperties.AmqpCredential = amqpCred.Clone(); return; } if (!tsec.IgnoreEndpointClientCredentials) { ClientCredentials cliCred = bindingContext.BindingParameters.Find<ClientCredentials>(); if (cliCred != null) { if (cliCred.UserName != null) { if (cliCred.UserName.UserName != null) { channelProperties.AmqpCredential = new AmqpCredential(cliCred.UserName.UserName, cliCred.UserName.Password); return; } } } } if (tsec.DefaultCredential != null) { channelProperties.AmqpCredential = tsec.DefaultCredential.Clone(); } }
public AmqpTransportBindingElement() { // start with default properties channelProperties = new AmqpChannelProperties(); }