public static InternalSession CreateInternalSession(XmlSetting entry) { string nm = entry.ReadSetting("@Name", ""); string brokerUri = entry.ReadSetting("@value"); object[] factoryParams = GetFactoryParams(entry.SelectOne("FactoryParams")); string clientId = entry.ReadSetting("ClientId/@value", null); // GetNodeValueAttribute(uriNode, "clientId", "NMSTestClientId"); string userName = entry.ReadSetting("UserName/@value"); //GetNodeValueAttribute(uriNode, "userName", "guest"); string passWord = entry.ReadSetting("PassWord/@value"); //GetNodeValueAttribute(uriNode, "passWord", "guest"); //string queueName = entry.ReadSetting("QueueName/@value"); //GetNodeValueAttribute(uriNode, "QueueName", "QueueName"); int timeout = 0; if (!int.TryParse(entry.ReadSetting("Timeout/@value", null), out timeout)) { timeout = 5; } try { Apache.NMS.NMSConnectionFactory nmsFactory = (null == factoryParams) ? new Apache.NMS.NMSConnectionFactory(brokerUri) : new Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams); IConnection newConnection = nmsFactory.ConnectionFactory.CreateConnection(userName, passWord); if (newConnection == null) { throw new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri)); } newConnection.RequestTimeout = TimeSpan.FromSeconds(timeout); if (!string.IsNullOrEmpty(clientId)) { newConnection.ClientId = clientId; } return(new InternalSession(nm, newConnection , entry.ReadSetting("modelDestinationName/@value") , entry.ReadSetting("alertDestinationName/@value") , entry.ReadSetting("perfDestinationName/@value") , entry.ReadSetting("deskDestinationName/@value"))); } catch (Exception e) { return(new InternalSession(nm, new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri), e))); } }
public static Session Create(XmlSetting xmlSetting) { InternalSession defaultSession = CreateInternalSession(xmlSetting.SelectOne("/configuration/MQs/DefaultMQ")); Session session = new Session(defaultSession); XmlSetting[] mqSettings = xmlSetting.Select("/configuration/MQs/MQ"); if (null == mqSettings || 0 == mqSettings.Length) { return(session); } foreach (XmlSetting mqSetting in mqSettings) { session.Add(CreateInternalSession(mqSetting)); } return(session); }
public static InternalSession CreateInternalSession(XmlSetting entry) { string nm = entry.ReadSetting("@Name", ""); string brokerUri = entry.ReadSetting("@value"); object[] factoryParams = GetFactoryParams(entry.SelectOne("FactoryParams")); string clientId = entry.ReadSetting("ClientId/@value", null);// GetNodeValueAttribute(uriNode, "clientId", "NMSTestClientId"); string userName = entry.ReadSetting("UserName/@value"); //GetNodeValueAttribute(uriNode, "userName", "guest"); string passWord = entry.ReadSetting("PassWord/@value"); //GetNodeValueAttribute(uriNode, "passWord", "guest"); //string queueName = entry.ReadSetting("QueueName/@value"); //GetNodeValueAttribute(uriNode, "QueueName", "QueueName"); int timeout = 0; if (!int.TryParse(entry.ReadSetting("Timeout/@value", null), out timeout)) timeout = 5; try { Apache.NMS.NMSConnectionFactory nmsFactory = (null == factoryParams) ? new Apache.NMS.NMSConnectionFactory(brokerUri) : new Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams); IConnection newConnection = nmsFactory.ConnectionFactory.CreateConnection(userName, passWord); if (newConnection == null) throw new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri)); newConnection.RequestTimeout = TimeSpan.FromSeconds(timeout); if (!string.IsNullOrEmpty(clientId)) newConnection.ClientId = clientId; return new InternalSession(nm, newConnection , entry.ReadSetting("modelDestinationName/@value") , entry.ReadSetting("alertDestinationName/@value") , entry.ReadSetting("perfDestinationName/@value") , entry.ReadSetting("deskDestinationName/@value")); } catch (Exception e) { return new InternalSession(nm, new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri), e)); } }
public static Session Create(XmlSetting xmlSetting) { InternalSession defaultSession = CreateInternalSession(xmlSetting.SelectOne("/configuration/MQs/DefaultMQ")); Session session = new Session(defaultSession); XmlSetting[] mqSettings = xmlSetting.Select("/configuration/MQs/MQ"); if (null == mqSettings || 0 == mqSettings.Length) return session; foreach (XmlSetting mqSetting in mqSettings) { session.Add(CreateInternalSession(mqSetting)); } return session; }