Ben 2 sınıfları oluşturmak zorunda SpringBoot ile RabbitMQ öğrenmeye çalışın. RabbitMQ Bahar çizme org.springframework.beans.factory.NoSuchBeanDefinitionException
public class Receiver {
private CountDownLatch latch = new CountDownLatch(1);
public void receiveMessage(String message) {
System.out.println("Received <" + message + ">");
latch.countDown();
}
public CountDownLatch getLatch() {
return latch;
}
}
Ve saniyesi sınıf RabbitMq2Application.java (o springBootApplication olan): benim iletisi.
org.springframework.beans.factory.NoSuchBeanDefinitionException
Ben ConnectionFactory o @autowired çünkü çünkü şüpheli:
@SpringBootApplication
public class RabbitMq2Application implements CommandLineRunner{
final static String queueName = "spring-boot";
@Autowired
AnnotationConfigApplicationContext context;
@Autowired
RabbitTemplate rabbitTemplate;
@Bean
Queue queue() {
return new Queue(queueName, false);
}
@Bean
TopicExchange exchange() {
return new TopicExchange("spring-boot-exchange");
}
@Bean
Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(queueName);
}
@Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(queueName);
container.setMessageListener(listenerAdapter);
return container;
}
@Bean
Receiver receiver() {
return new Receiver();
}
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
return new MessageListenerAdapter(receiver, "receiveMessage");
}
public static void main(String[] args) {
SpringApplication.run(RabbitMq2Application.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("Waiting five seconds...");
Thread.sleep(5000);
System.out.println("Sending message...");
rabbitTemplate.convertAndSend(queueName, "Hello from RabbitMQ!");
receiver().getLatch().await(10000, TimeUnit.MILLISECONDS);
context.close();
}
}
Ve bu hatayı alıyorum.