public ITransport CreateTransport(Uri location) { URISupport.CompositeData cd = URISupport.parseComposite(location); if (cd.Components.Length > 0) { agent.DiscoveryURI = cd.Components[0]; } if (!agent.IsStarted) { agent.Start(); } Uri hostUri = DiscoveredUri; if (null == hostUri) { // If a new broker is found the agent will fire an event which will result in discoveredUri being set. discoveredUriEvent.WaitOne(TIMEOUT_IN_SECONDS * 1000, true); hostUri = DiscoveredUri; if (null == hostUri) { throw new NMSConnectionException(String.Format("Unable to find a connection to {0} before the timeout period expired.", location.ToString())); } } TcpTransportFactory tcpTransFactory = new TcpTransportFactory(); return(tcpTransFactory.CompositeConnect(new Uri(hostUri + location.Query))); }
public void TestCompositePath() { URISupport.CompositeData data = URISupport.ParseComposite(new Uri("test:(test:path)/path")); Assert.AreEqual("path", data.Path); data = URISupport.ParseComposite(new Uri("test:test:path")); Assert.IsNull(data.Path); }
public void TestParseCompositeWithFragment() { string uriString = "failover:(tcp://localhost:61616,ssl://remotehost:61617?param=true#fragment)#fragment"; URISupport.CompositeData rc = URISupport.ParseComposite(new Uri(uriString)); Assert.IsTrue(rc.Components.Length == 2); Assert.AreEqual("failover", rc.Scheme); Assert.AreEqual("#fragment", rc.Fragment); Uri uri1 = rc.Components[0]; Uri uri2 = rc.Components[1]; Assert.AreEqual("tcp", uri1.Scheme); Assert.AreEqual("ssl", uri2.Scheme); Assert.AreEqual("localhost", uri1.Host); Assert.AreEqual("remotehost", uri2.Host); Assert.AreEqual(61616, uri1.Port); Assert.AreEqual(61617, uri2.Port); Assert.IsTrue(String.IsNullOrEmpty(uri1.Fragment)); Assert.IsNotNull(uri2.Fragment); Assert.AreEqual("#fragment", uri2.Fragment); Assert.AreEqual("?param=true", uri2.Query); }
public void TestEmptyCompositePath() { URISupport.CompositeData data = URISupport.ParseComposite( new Uri("broker:()/localhost?persistent=false")); Assert.AreEqual(0, data.Components.Length); }
public override ITransport CreateTransport(URISupport.CompositeData compositData) { StringDictionary options = compositData.Parameters; FailoverTransport failoverTransport = CreateTransport(options); return(CreateTransport(failoverTransport, compositData, options)); }
/// <summary> /// </summary> /// <param name="compositData"></param> /// <returns></returns> public ITransport CreateTransport(URISupport.CompositeData compositData) { StringDictionary options = compositData.Parameters; FailoverTransport transport = CreateTransport(options); transport.Add(compositData.Components); return(transport); }
public void TestParsingCompositeURI() { URISupport.CompositeData data = URISupport.ParseComposite( URISupport.CreateCompatibleUri("failover://(tcp://localhost:61616)?name=foo")); Assert.AreEqual(1, data.Components.Length, "one component"); Assert.AreEqual("localhost", data.Components[0].Host, "Component Host is incorrect"); Assert.AreEqual(61616, data.Components[0].Port, "Component Port is incorrect"); Assert.AreEqual(1, data.Parameters.Count, "Size: " + data.Parameters); }
public void TestCompositeWithComponentParam() { URISupport.CompositeData data = URISupport.ParseComposite(new Uri("test:(part1://host?part1=true)?outside=true")); Assert.AreEqual(1, data.Components.Length); Assert.AreEqual(1, data.Parameters.Count); StringDictionary part1Params = URISupport.ParseParameters(data.Components[0]); Assert.AreEqual(1, part1Params.Count); Assert.IsTrue(part1Params.ContainsKey("part1")); }
/// <summary> /// Creates a new session to work on this connection /// </summary> public ISession CreateSession(AcknowledgementMode sessionAcknowledgementMode) { SessionInfo info = CreateSessionInfo(sessionAcknowledgementMode); Session session = new Session(this, info, sessionAcknowledgementMode, this.dispatchAsync); // Set properties on session using parameters prefixed with "session." URISupport.CompositeData c = URISupport.parseComposite(this.brokerUri); URISupport.SetProperties(session, c.Parameters, "session."); if (IsStarted) { session.Start(); } sessions.Add(session); return(session); }
public IConnection CreateConnection(string userName, string password) { // Strip off the activemq prefix, if it exists. Uri uri = new Uri(URISupport.stripPrefix(brokerUri.OriginalString, "activemq:")); Tracer.InfoFormat("Connecting to: {0}", uri.ToString()); ConnectionInfo info = CreateConnectionInfo(userName, password); ITransport transport = TransportFactory.CreateTransport(uri); Connection connection = new Connection(uri, transport, info); // Set properties on connection using parameters prefixed with "connection." // Since this could be a composite Uri, assume the connection-specific parameters // are associated with the outer-most specification of the composite Uri. What's nice // is that this works with simple Uri as well. URISupport.CompositeData c = URISupport.parseComposite(uri); URISupport.SetProperties(connection, c.Parameters, "connection."); connection.ITransport.Start(); return(connection); }
public void TestComposite() { URISupport.CompositeData data = URISupport.ParseComposite( new Uri("test:(part1://host,part2://(sub1://part,sub2:part))")); Assert.AreEqual(2, data.Components.Length); }
public void TestSimpleComposite() { URISupport.CompositeData data = URISupport.ParseComposite(new Uri("test:tcp://part1")); Assert.AreEqual(1, data.Components.Length); }
/// <summary> /// Factory method for creating a DiscoveryTransport. The Discovery Transport wraps the /// given ICompositeTransport and will add and remove Transport URIs as they are discovered. /// </summary> public static DiscoveryTransport CreateTransport(ICompositeTransport compositeTransport, URISupport.CompositeData compositeData, StringDictionary options) { DiscoveryTransport transport = new DiscoveryTransport(compositeTransport); URISupport.SetProperties(transport, options, "transport."); transport.Properties = options; Uri discoveryAgentURI = compositeData.Components[0]; IDiscoveryAgent discoveryAgent = DiscoveryAgentFactory.CreateAgent(discoveryAgentURI); transport.DiscoveryAgent = discoveryAgent; return(transport); }