Exemplo n.º 1
0
        public void Subscribe()
        {
            var subscription = new UnityAmqpExchangeSubscription(
                txtexcname.text, AmqpExchangeTypes.Topic, txtroutkey.text,
                null, AmqpClient.Instance.UnityEventDebugExhangeMessageHandler);

            // Subscribe on the client
            AmqpClient.Subscribe(subscription);
        }
    // Handles a connection event
    void HandleConnected(AmqpClient client)
    {
        var subscription = new UnityAmqpExchangeSubscription("sensorData", AmqpExchangeTypes.Direct, "", null, handleIncomingMessage);

        amqp.SubscribeToExchange(subscription);

        subscription = new UnityAmqpExchangeSubscription("chairs", AmqpExchangeTypes.Direct, "", null, handleIncomingMessageChairs);
        amqp.SubscribeToExchange(subscription);
    }
        /// <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);
        }