No, beep, code
Mainly for consumers to add configuration
1.Put the configuration in the configuration center (it can also be put on the consumer service)
listener.direct.auto -Startup is set to false,
Then add rabbitmq.start As startup property
spring:
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
listener:
direct:
auto-startup: false
rabbitmq:
start: true
Then in the consumer service startup class xxxxxApplication.class Add in
package com.test.service1;
import com.test.rabbitmq.RabbitmqApplication;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import javax.annotation.Resource;
@SpringBootApplication
@EnableEurekaClient
public class Service1Application {
public static void main(String[] args) {
ApplicationContext context=SpringApplication.run(Service1Application.class, args);
RabbitMQStart rabbitMQRun = context.getBean(RabbitMQStart.class);
rabbitMQRun.start();
}
@Bean
public RabbitMQStart rabbitMQRun() {
return new RabbitMQStart();
}
private static class RabbitMQStart {
//In order to use the @value annotation in the static method in main only this way can be used
@Value("${rabbitmq.start}")
private Boolean rabbitmqStart;
@Resource
RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry;
public void start() {
if(rabbitmqStart)
rabbitListenerEndpointRegistry.start();
else
rabbitListenerEndpointRegistry.stop();
System.out.println("=================== Rabbitmq:"+rabbitmqStart+"===================");
}
}
}
2.Test:
rabbitmq.start =When true
rabbitmq.start =When false
Read More:
- [Solved] Springboot Project Startup Error: Unable to Identify bootstrap.yml Configuration
- Springboot integration RabbitMQ times error: Failed to check/redeclare auto-delete queue(s).
- [Solved] Springboot Package jar and Startup Error: It was loaded from the following location
- Springboot error about swagger startup [How to Solve]
- Springboot startup error “No bean named’org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry’ available”
- Springboot startup error: err config is disabled command (Redis Disables Config command)
- [Solved] SpringBoot Startup Error: Unable to start LiveReload server
- Springboot Files Upload Limit Error: The field file exceeds its maximum permitted size of 1048576 bytes
- [Solved] SpringBoot Startup Error: org.springframework.beans.factory.UnsatisfiedDependencyException Error creating
- Configuration of springboot + Druid connection pool
- [Solved] SpringBoot+Dubbo Startup Error: Fail to start server(url dubbo192.168.0.920880service
- [Solved] SpringBoot+Dubbo Startup Error: Fail to start server(url: dubbo://192.168.0.9:20880/service
- How to Solve Springboot Upload Files Error: The field XXX exceeds its maximum permitted size of 1048576 bytes
- Springboot startup error: Field elasticsearchRestTemplate in cn.lili.modules.material.serviceImpl.QrMaterialServiceImpl required a bean of type
- SpringBoot—Error starting ApplicationContext. To display the auto-configuration report re-run your a
- [Solved] IDEA springboot Startup Error: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path
- SpringBoot Startup Error: Failed to start component [Connector[HTTP/1.1-8080]]
- [Solved] SpringBoot Project Startup Error: Field userMapper in com.demo.controller.MemberController required a bean of type ‘c
- IDEA springboot can recognize POM files, but suddenly it can’t reference mven dependencies. Strange things, inexplicable solutions
- The @value annotation of springboot adds the default value to solve the startup error caused by the non-existent key