Hi Mark,
okay I changed my producer and consumer configuration as follows:
Consumer:
Code:
@Value("${service.command.pattern}")
private String commandRoutingKey;
@Bean
public SimpleMessageListenerContainer listenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory());
container.setQueueNames(this.queueName);
container.setMessageListener(messageListenerAdapter());
return container;
}
@Bean
public MessageListenerAdapter messageListenerAdapter() {
return new MessageListenerAdapter(new ServiceBroker());
}
@Bean
public Queue commandQueue() {
return amqpAdmin().declareQueue();
}
@Bean
public Binding marketDataBinding() {
return BindingBuilder.bind(
commandQueue()).to(commandExchange()).with(commandRoutingKey);
}
Producer:
Code:
@Bean
public ScheduledProducer scheduledProducer() {
return new ScheduledProducer();
}
@Bean
public BeanPostProcessor postProcessor() {
return new ScheduledAnnotationBeanPostProcessor();
}
static class ScheduledProducer {
@Autowired
private volatile RabbitTemplate rabbitTemplate;
protected final String queueName = "service";
protected final String topicExchange = "service.command";
@Scheduled(fixedRate = 3000)
public void sendMessage() {
rabbitTemplate.convertAndSend(topicExchange, queueName, "This is a test message");
}
}
But still no messages... :-(
AbstractConfiguration looks like this:
Code:
protected final String vhost = "";
protected final String vhostUser = "guest";
protected final String vhostPassword = "guest";
private int port = 5672;
protected final String queueName = "service";
protected final String topicExchange = "service.command";
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
//connectionFactory.setVirtualHost(vhost);
connectionFactory.setPort(port);
connectionFactory.setUsername(vhostUser);
connectionFactory.setPassword(vhostPassword);
return connectionFactory;
}
@Bean
public AmqpAdmin amqpAdmin() {
return new RabbitAdmin(connectionFactory());
}
@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(connectionFactory());
template.setQueue(this.queueName);
template.setExchange(this.topicExchange);
template.setRoutingKey(this.queueName);
return template;
}
@Bean
public Queue serviceQueue() {
Queue queue = new Queue(this.queueName);
return queue;
}
@Bean
public TopicExchange commandExchange() {
return new TopicExchange(topicExchange, true, false);
}
Could you help me out with that? I don't know what I am actually doing wrong... :-(
Thanks Johannes