Exemplo n.º 1
0
        public void AddListener(string targetAddress)
        {
            if (!IsOpen)
            {
                throw new Exception("The Endpoint must have an a request processor set up via the Open method in order to receive messages on a listener.");
            }

            string t = targetAddress.ToUpper();

            if (listeners.ContainsKey(t))
            {
                throw new Exception("The specified targetAddress is already in use.");
            }

            Exception ex = null;

            try
            {
                InternalMessageProcessor p = new InternalMessageProcessor(this, targetAddress);
                inboundHost.RegisterMessageProcessor(targetAddress, p);
                AppLog.Info($"Listener registered on {targetAddress}");
                listeners[t] = p;
            }
            catch (Exception exception)
            {
                ex = exception;
                AppLog.Error(ex);
            }

            if (ex != null)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public void RemoveListener(string targetAddress)
        {
            string t = targetAddress.ToUpper();

            if (!listeners.ContainsKey(t))
            {
                throw new Exception("The specified targetAddress does not have an active listener.");
            }
            inboundHost.UnregisterMessageProcessor(targetAddress);
            InternalMessageProcessor p = null;

            while (!listeners.TryRemove(targetAddress, out p))
            {
                Task.Yield();
            }
        }