AMQP-164: fixed parsers
This commit is contained in:
@@ -75,4 +75,9 @@ public class Binding {
|
||||
return DestinationType.QUEUE.equals(destinationType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Binding [destination=" + destination + ", exchange=" + exchange + ", routingKey=" + routingKey + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.Binding.DestinationType;
|
||||
import org.springframework.amqp.core.Exchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class BindingFactoryBean implements FactoryBean<Binding> {
|
||||
|
||||
private Map<String, Object> arguments;
|
||||
private String routingKey = "";
|
||||
private String exchange;
|
||||
private Queue destinationQueue;
|
||||
private Exchange destinationExchange;
|
||||
|
||||
public void setArguments(Map<String, Object> arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public void setRoutingKey(String routingKey) {
|
||||
this.routingKey = routingKey;
|
||||
}
|
||||
|
||||
public void setExchange(String exchange) {
|
||||
this.exchange = exchange;
|
||||
}
|
||||
|
||||
public void setDestinationQueue(Queue destinationQueue) {
|
||||
this.destinationQueue = destinationQueue;
|
||||
}
|
||||
|
||||
public void setDestinationExchange(Exchange destinationExchange) {
|
||||
this.destinationExchange = destinationExchange;
|
||||
}
|
||||
|
||||
public Binding getObject() throws Exception {
|
||||
String destination;
|
||||
DestinationType destinationType;
|
||||
if (destinationQueue != null) {
|
||||
destination = destinationQueue.getName();
|
||||
destinationType = DestinationType.QUEUE;
|
||||
} else {
|
||||
destination = destinationExchange.getName();
|
||||
destinationType = DestinationType.EXCHANGE;
|
||||
}
|
||||
return new Binding(destination, destinationType, exchange, routingKey, arguments);
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return Binding.class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,8 +15,6 @@ package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.Binding.DestinationType;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -41,16 +39,15 @@ public class DirectExchangeParser extends AbstractExchangeParser {
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding,
|
||||
ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
|
||||
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
|
||||
builder.addConstructorArgValue(DestinationType.EXCHANGE);
|
||||
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BindingFactoryBean.class);
|
||||
builder.addPropertyReference("destinationQueue", binding.getAttribute(BINDING_QUEUE_ATTR));
|
||||
builder.addPropertyValue("exchange", new TypedStringValue(exchangeName));
|
||||
String bindingKey = binding.getAttribute(BINDING_KEY_ATTR);
|
||||
if (!StringUtils.hasText(bindingKey)) {
|
||||
bindingKey = "";
|
||||
}
|
||||
builder.addConstructorArgValue(new TypedStringValue(bindingKey));
|
||||
builder.addConstructorArgValue(Collections.<String, Object>emptyMap());
|
||||
builder.addPropertyValue("routingKey", new TypedStringValue(bindingKey));
|
||||
builder.addPropertyValue("arguments", Collections.<String, Object>emptyMap());
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.Binding.DestinationType;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -37,12 +35,10 @@ public class FanoutExchangeParser extends AbstractExchangeParser {
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
|
||||
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
|
||||
builder.addConstructorArgValue(DestinationType.EXCHANGE);
|
||||
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
|
||||
builder.addConstructorArgValue("");
|
||||
builder.addConstructorArgValue(Collections.<String, Object>emptyMap());
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BindingFactoryBean.class);
|
||||
builder.addPropertyReference("destinationQueue", binding.getAttribute(BINDING_QUEUE_ATTR));
|
||||
builder.addPropertyValue("exchange", new TypedStringValue(exchangeName));
|
||||
builder.addPropertyValue("arguments", Collections.<String, Object>emptyMap());
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.Binding.DestinationType;
|
||||
import org.springframework.amqp.core.HeadersExchange;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -39,16 +37,14 @@ public class HeadersExchangeParser extends AbstractExchangeParser {
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
|
||||
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
|
||||
builder.addConstructorArgValue(DestinationType.EXCHANGE);
|
||||
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
|
||||
builder.addConstructorArgValue("");
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BindingFactoryBean.class);
|
||||
builder.addPropertyReference("destinationQueue", binding.getAttribute(BINDING_QUEUE_ATTR));
|
||||
builder.addPropertyValue("exchange", new TypedStringValue(exchangeName));
|
||||
ManagedMap<TypedStringValue, TypedStringValue> map = new ManagedMap<TypedStringValue, TypedStringValue>();
|
||||
String key = binding.getAttribute("key");
|
||||
String value = binding.getAttribute("value");
|
||||
map.put(new TypedStringValue(key), new TypedStringValue(value));
|
||||
builder.addConstructorArgValue(map);
|
||||
builder.addPropertyValue("arguments", map);
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.Binding.DestinationType;
|
||||
import org.springframework.amqp.core.TopicExchange;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -42,12 +40,11 @@ public class TopicExchangeParser extends AbstractExchangeParser {
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
|
||||
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
|
||||
builder.addConstructorArgValue(DestinationType.EXCHANGE);
|
||||
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
|
||||
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_PATTERN_ATTR)));
|
||||
builder.addConstructorArgValue(Collections.<String, Object>emptyMap());
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BindingFactoryBean.class);
|
||||
builder.addPropertyReference("destinationQueue", binding.getAttribute(BINDING_QUEUE_ATTR));
|
||||
builder.addPropertyValue("exchange", new TypedStringValue(exchangeName));
|
||||
builder.addPropertyValue("routingKey", new TypedStringValue(binding.getAttribute(BINDING_PATTERN_ATTR)));
|
||||
builder.addPropertyValue("arguments", Collections.<String, Object>emptyMap());
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user