(Thirty-six) spring cloud micro Services Architecture b2b2c e-commerce - Configuration Center and message bus

Please add source e-commerce platform Penguin beg: 3536247259. Spring cloud bus connecting the nodes proxy distribution by lightweight messages. This change in status with the broadcast (e.g., configuration change) command, or other messages. Spring bus a core idea is to extend the spring boot application distributed by the starter, it can also be used to establish a communication channel between multiple applications. The only way to achieve is to use AMQP as a message broker channel, the same set of characteristics (some depending on the channel settings) in the document more channels.

Spring cloud bus have been translated into many domestic message bus, but also very image. We can be understood as all distributed project management and dissemination of information can, in fact, the essence is to use a broadcast mechanism MQ spread messages in a distributed system, currently used have Kafka and RabbitMQ. Spring Cloud Bus do step configuration updates:

1, triggering post commit code to the client terminal A sends a bus / refresh

2, client A receives a request to update the configuration from the terminal and sent to the Server Spring Cloud Bus

3, Spring Cloud bus and receive messages to notify other clients

4, other client receives a notification request Server clients to obtain the latest configuration

5, all clients are to get the latest configuration

Examples of projects

Client spring-cloud-config-client transformation

1, adding a dependency

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

We need more introduction spring-cloud-starter-bus-amqp package, adding support for message bus

2, the configuration file

## 刷新时,关闭安全验证
management.security.enabled=false
## 开启消息跟踪
spring.cloud.bus.trace.enabled=true
 
spring.rabbitmq.host=192.168.9.89
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456

The need to increase the profile configuration RebbitMq, so that the client code transformation is complete.

3, the test
in order to start spring-cloud-eureka, spring- cloud-config-server, spring-cloud-config-client project, start the spring-cloud-config-client project we will find such a starting log output recording.

2017-05-26 17:05:38.568  INFO 21924 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/bus/refresh],methods=[POST]}" onto public void org.springframework.cloud.bus.endpoint.RefreshBusEndpoint.refresh(java.lang.String)

Description The client already has the ability to notice the message bus, in order to better simulate the message bus, we change the port the client spring-cloud-config-client project for 8003,8004 to start up such a test environment is ready a.
We were the first to test the server and the client is running correctly, visit: HTTP: // localhost: 8001 / Neo-config / dev, return information:

{
    "name": "neo-config", 
    "profiles": [
        "dev"
    ], 
    "label": null, 
    "version": null, 
    "state": null, 
    "propertySources": [
        {
            "name": "https://github.com/ityouknow/spring-cloud-starter/config-repo/neo-config-dev.properties", 
            "source": {
                "neo.hello": "hello im dev"
            }
        }
    ]
}

DESCRIPTION server side are normal to read configuration information.

In order to access: HTTP: // localhost: 8002 / the Hello, HTTP: // localhost: 8003 / the Hello, HTTP: // localhost: 8004 / the Hello, return: the Hello IM dev. Description Client have read the contents of the server side.

Now we update neo-config-dev.properties in neo.hello value hello im dev update and submit to the code repository, access: HTTP: // localhost: 8002 / the Hello still return hello im dev. Our port is 8002 client sends a / bus post request / refresh of. In the following command to simulate win webhook.

curl -X POST http://localhost:8002/bus/refresh

After execution, in order to access: HTTP: // localhost: 8002 / the Hello, HTTP: // localhost: 8003 / the Hello, HTTP: // localhost: 8004 / the Hello, return: the Hello IM dev Update. Description three clients have already got the latest information on the configuration file, so that we achieve an example.

Guess you like

Origin blog.csdn.net/wiyzq/article/details/90897111