예제 #1
0
 public static ProxyListener GetListener(Uri queueUri)
 {
     if (_instance == null)
     {
         lock (typeof(ProxyListener))
         {
             if (_instance == null)
             {
                 _instance = new ProxyListener {
                     QueueUri = queueUri
                 };
             }
         }
     }
     return(_instance);
 }
예제 #2
0
 /// <summary>
 /// Method responsible for creating the Connection,
 /// Channel, ReplyQueue, and DataPortalQueueName values
 /// used for bi-directional communication.
 /// </summary>
 protected virtual void InitializeRabbitMQ()
 {
     if (Connection == null)
     {
         var url = new Uri(DataPortalUrl);
         Console.WriteLine($"Initializing {DataPortalUrl}");
         if (url.Scheme != "rabbitmq")
         {
             throw new UriFormatException("Scheme != rabbitmq://");
         }
         if (string.IsNullOrWhiteSpace(url.Host))
         {
             throw new UriFormatException("Host");
         }
         DataPortalQueueName = url.AbsolutePath.Substring(1);
         if (string.IsNullOrWhiteSpace(DataPortalQueueName))
         {
             throw new UriFormatException("DataPortalQueueName");
         }
         Console.WriteLine($"Will send to queue {DataPortalQueueName}");
         var factory = new ConnectionFactory()
         {
             HostName = url.Host
         };
         if (url.Port < 0)
         {
             factory.Port = url.Port;
         }
         var userInfo = url.UserInfo.Split(':');
         if (userInfo.Length > 0 && !string.IsNullOrWhiteSpace(userInfo[0]))
         {
             factory.UserName = userInfo[0];
         }
         if (userInfo.Length > 1)
         {
             factory.Password = userInfo[1];
         }
         Connection = factory.CreateConnection();
         Channel    = Connection.CreateModel();
         if (QueueListener == null)
         {
             QueueListener = ProxyListener.GetListener(url);
             QueueListener.StartListening();
         }
     }
 }