/// <summary>
        /// Subscribes to the AMQP exchange subscription using the form's values.
        /// </summary>
        public void Subscribe()
        {
            // Validate args
            var isValid = true;

            var exchangeName = ExchangeName.options[ExchangeName.value].text;

            if (string.IsNullOrEmpty(exchangeName))
            {
                isValid           = false;
                AmqpConsole.Color = Color.red;
                AmqpConsole.WriteLine("* Exchange Name cannot be blank");
                AmqpConsole.Color = null;
            }

            // Don't continue if values are invald
            if (!isValid)
            {
                return;
            }

            var exchangeType = AmqpExchangeTypes.Direct;

            // Find this exchange and get its exchange type
            foreach (var exchange in exchanges)
            {
                if (exchange.Name == exchangeName)
                {
                    exchangeType = exchange.Type;
                    break;
                }
            }

            var routingKey = RoutingKey.text;

            // Ensure this subscription doesn't already exist
            foreach (var sub in exSubscriptions)
            {
                if (sub.ExchangeName == exchangeName && sub.ExchangeType == exchangeType && sub.RoutingKey == routingKey)
                {
                    AmqpConsole.Color = new Color(1f, 0.5f, 0);
                    AmqpConsole.WriteLineFormat("Subscription already exists for exchange {0}:{1}", exchangeName, routingKey);
                    AmqpConsole.Color = null;
                    return;
                }
            }

            // Create the new subscription
            var subscription = new UnityAmqpExchangeSubscription(exchangeName, exchangeType, routingKey, null, AmqpClient.Instance.UnityEventDebugExhangeMessageHandler);

            // Subscribe on the client
            AmqpClient.Subscribe(subscription);
        }
        /// <summary>
        /// Unsubscribes from the AMQP exchange subscription using the form's values.
        /// </summary>
        public void Unsubscribe()
        {
            // Validate args
            var isValid = true;

            var exchangeName = ExchangeName.options[ExchangeName.value].text;

            if (string.IsNullOrEmpty(exchangeName))
            {
                isValid           = false;
                AmqpConsole.Color = Color.red;
                AmqpConsole.WriteLine("* Exchange Name cannot be blank");
                AmqpConsole.Color = null;
            }

            // Don't continue if values are invald
            if (!isValid)
            {
                return;
            }

            var exchangeType = AmqpExchangeTypes.Direct;

            // Find this exchange and get its exchange type
            foreach (var exchange in exchanges)
            {
                if (exchange.Name == exchangeName)
                {
                    exchangeType = exchange.Type;
                    break;
                }
            }

            var routingKey = RoutingKey.text;

            // Ensure this subscription already exists
            var subs = exSubscriptions.ToArray();

            foreach (var sub in subs)
            {
                if (sub.ExchangeName == exchangeName && sub.ExchangeType == exchangeType && sub.RoutingKey == routingKey)
                {
                    AmqpClient.Unsubscribe(sub);
                    exSubscriptions.Remove(sub);
                    return;
                }
            }

            AmqpConsole.Color = new Color(1f, 0.5f, 0);
            AmqpConsole.WriteLineFormat("Subscription not found for exchange {0}:{1}", exchangeName, routingKey);
            AmqpConsole.Color = null;
        }
Ejemplo n.º 3
0
        public void UnsubscribeQueue()
        {
            Debug.Log("UnsubscribeQueue");
            var queueName = SubscribeQueueName.text;

            foreach (var sub in queueSubscriptions)
            {
                if (sub.QueueName == queueName)
                {
                    AmqpClient.Unsubscribe(sub);
                    AmqpConsole.Color = new Color(0f, 1f, 0);
                    AmqpConsole.WriteLineFormat("Unsubscribed for queue {0}", sub.QueueName);
                    AmqpConsole.Color = null;
                    return;
                }
            }

            AmqpConsole.Color = new Color(1f, 0f, 0);
            AmqpConsole.WriteLineFormat("NO Subscription exists for queue {0}", queueName);
            AmqpConsole.Color = null;
        }
Ejemplo n.º 4
0
        public void SubscribeQueue()
        {
            Debug.Log("SubscribeQueue");
            var queueName = SubscribeQueueName.text;

            // Ensure this subscription doesn't already exist
            foreach (var sub in queueSubscriptions)
            {
                if (sub.QueueName == queueName)
                {
                    AmqpConsole.Color = new Color(1f, 0.5f, 0);
                    AmqpConsole.WriteLineFormat("Subscription already exists for queue {0}", queueName);
                    AmqpConsole.Color = null;
                    return;
                }
            }

            var subscription = new UnityAmqpQueueSubscription(SubscribeQueueName.text, true, null,
                                                              UnityEventDebugQueueMessageHandler);

            AmqpClient.Subscribe(subscription);
        }