AMQP-12 added Exchanges, Queues, and Bindings in a lifecycle callback rather than at configuration time
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user