Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.Binding


  @RequestMapping(value="/binding", method=RequestMethod.POST)
  @ResponseBody
  public Binding addBinding(@RequestParam String routingKey) {
    try {
      admin.removeBinding(binding);
      Binding binding = BindingBuilder.bind(logQueue).to(exchange).with(routingKey);
      admin.declareBinding(binding);
      this.binding = binding;
    } catch (RuntimeException e) {
      // TODO: create a new BindingResult object to carry back error message
      logger.error("Failed to declare queue or bind it with exchage", e);
View Full Code Here


            LOG.info("Declared queue {} for endpoint {}.", queue.getName(), endpoint);
            return queue;
        }

        protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
            Binding binding = null;

            //Is this a header exchange? Bind the key/value pair(s)
            if(exchange instanceof HeadersExchange) {
                if(this.endpoint.routingKey == null)
                    throw new IllegalStateException("Specified a header exchange without a key/value match");

                if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
                    throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");

                Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
                BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
                if(this.endpoint.routingKey.contains("|"))
                    binding = mapConfig.whereAny(keyValues).match();
                else
                    binding = mapConfig.whereAll(keyValues).match();

            //Is this a fanout exchange? Just bind the queue and exchange directly
            } else if(exchange instanceof FanoutExchange) {
                binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);

            //Perform routing key binding for direct or topic exchanges
            } else {
                binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
            }

            if (this.endpoint.isUsingDefaultExchange()) {
                LOG.info("Using default exchange for endpoint {}.  Default exchange is implicitly bound to every queue, with a routing key equal to the queue name.", endpoint);
            } else if (binding != null) {
                LOG.info("Declaring binding {} for endpoint {}.", binding.getRoutingKey(), endpoint);
                this.endpoint.getAmqpAdministration().declareBinding(binding);
            }

            return binding;
        }
View Full Code Here

            LOG.info("Declared queue {}", queue.getName());
            return queue;
        }

        protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
            Binding binding = null;

            //Is this a header exchange? Bind the key/value pair(s)
            if(exchange instanceof HeadersExchange) {
                if(this.endpoint.routingKey == null)
                    throw new IllegalStateException("Specified a header exchange without a key/value match");

                if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
                    throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");

                Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
                BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
                if(this.endpoint.routingKey.contains("|"))
                    binding = mapConfig.whereAny(keyValues).match();
                else
                    binding = mapConfig.whereAll(keyValues).match();

                //Is this a fanout exchange? Just bind the queue and exchange directly
            } else if(exchange instanceof FanoutExchange) {
                binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);

                //Perform routing key binding for direct or topic exchanges
            } else {
                binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
            }

            if(this.endpoint.isUsingDefaultExchange()) {
                LOG.info("Default exchange is implicitly bound to every queue, with a routing key equal to the queue name");
            } else if (binding != null) {
                LOG.info("Declaring binding {}", binding.getRoutingKey());
                this.endpoint.getAmqpAdministration().declareBinding(binding);
            }

            return binding;
        }
View Full Code Here

            LOG.info("Declared queue {} for endpoint {}.", queue.getName(), endpoint);
            return queue;
        }

        protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
            Binding binding = null;

            //Is this a header exchange? Bind the key/value pair(s)
            if(exchange instanceof HeadersExchange) {
                if(this.endpoint.routingKey == null)
                    throw new IllegalStateException("Specified a header exchange without a key/value match");

                if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
                    throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");

                Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
                BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
                if(this.endpoint.routingKey.contains("|"))
                    binding = mapConfig.whereAny(keyValues).match();
                else
                    binding = mapConfig.whereAll(keyValues).match();

            //Is this a fanout exchange? Just bind the queue and exchange directly
            } else if(exchange instanceof FanoutExchange) {
                binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);

            //Perform routing key binding for direct or topic exchanges
            } else {
                binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
            }

            if (this.endpoint.isUsingDefaultExchange()) {
                LOG.info("Using default exchange for endpoint {}.  Default exchange is implicitly bound to every queue, with a routing key equal to the queue name.", endpoint);
            } else if (binding != null) {
                LOG.info("Declaring binding {} for endpoint {}.", binding.getRoutingKey(), endpoint);
                this.endpoint.getAmqpAdministration().declareBinding(binding);
            }

            return binding;
        }
View Full Code Here

            LOG.info("Declared queue {} for endpoint {}.", queue.getName(), endpoint);
            return queue;
        }

        protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
            Binding binding = null;

            //Is this a header exchange? Bind the key/value pair(s)
            if(exchange instanceof HeadersExchange) {
                if(this.endpoint.routingKey == null)
                    throw new IllegalStateException("Specified a header exchange without a key/value match");

                if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
                    throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");

                Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
                BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
                if(this.endpoint.routingKey.contains("|"))
                    binding = mapConfig.whereAny(keyValues).match();
                else
                    binding = mapConfig.whereAll(keyValues).match();

            //Is this a fanout exchange? Just bind the queue and exchange directly
            } else if(exchange instanceof FanoutExchange) {
                binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);

            //Perform routing key binding for direct or topic exchanges
            } else {
                binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
            }

            if (this.endpoint.isUsingDefaultExchange()) {
                LOG.info("Using default exchange for endpoint {}.  Default exchange is implicitly bound to every queue, with a routing key equal to the queue name.", endpoint);
            } else if (binding != null) {
                LOG.info("Declaring binding {} for endpoint {}.", binding.getRoutingKey(), endpoint);
                this.endpoint.getAmqpAdministration().declareBinding(binding);
            }

            return binding;
        }
View Full Code Here

            LOG.info("Declared queue {} for endpoint {}.", queue.getName(), endpoint);
            return queue;
        }

        protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
            Binding binding = null;

            //Is this a header exchange? Bind the key/value pair(s)
            if(exchange instanceof HeadersExchange) {
                if(this.endpoint.routingKey == null)
                    throw new IllegalStateException("Specified a header exchange without a key/value match");

                if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
                    throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");

                Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
                BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
                if(this.endpoint.routingKey.contains("|"))
                    binding = mapConfig.whereAny(keyValues).match();
                else
                    binding = mapConfig.whereAll(keyValues).match();

            //Is this a fanout exchange? Just bind the queue and exchange directly
            } else if(exchange instanceof FanoutExchange) {
                binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);

            //Perform routing key binding for direct or topic exchanges
            } else {
                binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
            }

            if (this.endpoint.isUsingDefaultExchange()) {
                LOG.info("Using default exchange for endpoint {}.  Default exchange is implicitly bound to every queue, with a routing key equal to the queue name.", endpoint);
            } else if (binding != null) {
                LOG.info("Declaring binding {} for endpoint {}.", binding.getRoutingKey(), endpoint);
                this.endpoint.getAmqpAdministration().declareBinding(binding);
            }

            return binding;
        }
View Full Code Here

            rabbitAdmin.declareQueue(q);
          }
          currentQueue = q;

          if (null != currentExchange) {
            Binding binding = null;
            if (currentExchange instanceof FanoutExchange) {
              binding = BindingBuilder.bind(q).to((FanoutExchange) currentExchange);
            } else if (currentExchange instanceof DirectExchange) {
              binding = BindingBuilder.bind(q).to((DirectExchange) currentExchange).with(routingKey);
            } else if (currentExchange instanceof HeadersExchange) {
View Full Code Here

            LOG.info("Declared queue {} for endpoint {}.", queue.getName(), endpoint);
            return queue;
        }

        protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
            Binding binding = null;

            //Is this a header exchange? Bind the key/value pair(s)
            if(exchange instanceof HeadersExchange) {
                if(this.endpoint.routingKey == null)
                    throw new IllegalStateException("Specified a header exchange without a key/value match");

                if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
                    throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");

                Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
                BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
                if(this.endpoint.routingKey.contains("|"))
                    binding = mapConfig.whereAny(keyValues).match();
                else
                    binding = mapConfig.whereAll(keyValues).match();

            //Is this a fanout exchange? Just bind the queue and exchange directly
            } else if(exchange instanceof FanoutExchange) {
                binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);

            //Perform routing key binding for direct or topic exchanges
            } else {
                binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
            }

            if (this.endpoint.isUsingDefaultExchange()) {
                LOG.info("Using default exchange for endpoint {}.  Default exchange is implicitly bound to every queue, with a routing key equal to the queue name.", endpoint);
            } else if (binding != null) {
                LOG.info("Declaring binding {} for endpoint {}.", binding.getRoutingKey(), endpoint);
                this.endpoint.getAmqpAdministration().declareBinding(binding);
            }

            return binding;
        }
View Full Code Here

  }

  @Bean
  public Binding binding() {
    amqpAdmin().declareQueue(new Queue(queueName));
    Binding binding = new Binding(new Queue(queueName), new DirectExchange(exchange), routingKey);
    amqpAdmin().declareBinding(binding);
    return binding;
  }
View Full Code Here

    GenericApplicationContext context = new GenericApplicationContext();
    Queue queue = new Queue("foo");
    context.getBeanFactory().registerSingleton("foo", queue);
    DirectExchange exchange = new DirectExchange("bar");
    context.getBeanFactory().registerSingleton("bar", exchange);
    Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null);
    context.getBeanFactory().registerSingleton("baz", binding);
    context.refresh();
    admin.setApplicationContext(context);
    admin.afterPropertiesSet();
    assertNotNull(listener.get());
View Full Code Here

TOP

Related Classes of org.springframework.amqp.core.Binding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.