AMQP-12 added Exchanges, Queues, and Bindings in a lifecycle callback rather than at configuration time

This commit is contained in:
Mark Fisher
2010-07-09 13:40:07 -07:00
committed by Dave Syer
parent 822317679a
commit 3352b8d5f7
5 changed files with 11 additions and 37 deletions

View File

@@ -12,7 +12,7 @@ public class ConsumerConfiguration extends RabbitConfiguration {
public SimpleMessageListenerContainer listenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory());
container.setQueueName(helloWorldQueue.getName());
container.setQueueName(this.helloWorldQueueName);
container.setMessageListener(new MessageListenerAdapter(new HelloWorldHandler()));
return container;
}

View File

@@ -1,20 +1,17 @@
package org.springframework.amqp.helloworld;
import javax.annotation.PostConstruct;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.AbstractRabbitConfiguration;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitConfiguration extends AbstractRabbitConfiguration {
protected Queue helloWorldQueue = new Queue("hello.world.queue");
protected final String helloWorldQueueName = "hello.world.queue";
@Bean
public ConnectionFactory connectionFactory() {
@@ -28,24 +25,16 @@ public class RabbitConfiguration extends AbstractRabbitConfiguration {
public RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(connectionFactory());
//The routing key is set to the name of the queue by the broker for the default exchange.
template.setRoutingKey(helloWorldQueue.getName());
template.setRoutingKey(this.helloWorldQueueName);
//Where we will synchronously receive messages from
template.setQueue(helloWorldQueue.getName());
template.setQueue(this.helloWorldQueueName);
return template;
}
@PostConstruct
@SuppressWarnings("unused")
private void configureBroker() {
declare(helloWorldQueue);
}
/*
@Bean
public Queue helloWorldQueue()
{
return declare(helloWorldQueue);
}*/
public Queue helloWorldQueue() {
return new Queue(this.helloWorldQueueName);
}
/*
//Each queue is bound to the default direct exchange

View File

@@ -52,8 +52,6 @@ public abstract class AbstractStockAppRabbitConfiguration extends AbstractRabbit
*/
protected static String STOCK_REQUEST_ROUTING_KEY = STOCK_REQUEST_QUEUE_NAME;
//protected static TopicExchange MARKET_DATA_EXCHANGE = new TopicExchange(MARKET_DATA_EXCHANGE_NAME);
protected abstract void configureRabbitTemplate(RabbitTemplate template);
@@ -80,19 +78,9 @@ public abstract class AbstractStockAppRabbitConfiguration extends AbstractRabbit
return new JsonMessageConverter();
}
// @PostConstruct
// public void declareExchange()
// {
// declare(this.MARKET_DATA_EXCHANGE);
// }
@Bean
public TopicExchange marketDataExchange() {
return declare(new TopicExchange(MARKET_DATA_EXCHANGE_NAME));
return new TopicExchange(MARKET_DATA_EXCHANGE_NAME);
}
}

View File

@@ -114,7 +114,7 @@ public class RabbitClientConfiguration extends AbstractStockAppRabbitConfigurati
*/
@Bean
public Binding marketDataBinding() {
return declare(new Binding(marketDataQueue(), marketDataExchange(), marketDataRoutingKey));
return new Binding(marketDataQueue(), marketDataExchange(), marketDataRoutingKey);
// Using BindingBuilder
//return declareBinding(from(marketDataQueue()).to(marketDataExchange()).with(marketDataRoutingKey));
@@ -128,5 +128,4 @@ public class RabbitClientConfiguration extends AbstractStockAppRabbitConfigurati
return randomNameQueueDefinition();
}
}

View File

@@ -45,9 +45,7 @@ public class RabbitServerConfiguration extends AbstractStockAppRabbitConfigurati
*/
@Bean
public Queue stockRequestQueue() {
return declare(new Queue(STOCK_REQUEST_QUEUE_NAME));
return new Queue(STOCK_REQUEST_QUEUE_NAME);
}
}