The use of dubbo and application demo


1. Background description I
came into contact with dubbo too late. Since the company's underlying communication is too troublesome to be transformed, I understand the structure while I am, record the precautions here, and post some pits for encouragement
. 2. Understand what dubbo
1. What is dubbo?
1.1: dubbo is a service framework. If there is no distributed requirement, it is actually unnecessary. Only when it is distributed, there is a need for a distributed service framework like dubbo.
2. Features
2.1: Remote communication: provide Various abstract encapsulation of NIO framework based on long connection (http), including various threading models, serialization, and "request-response" mode of information exchange
2.2: Cluster fault tolerance: including multi-protocol support, and soft load balancing, failure Fault tolerance (the registry returns the service provider address list to the consumer, if there is a change, the registry will push the change data to the consumer based on the long connection), address routing, dynamic configuration, etc. Cluster support
2.3: automatic discovery: no need to write dead The address of the service provider, the registration center queries the IP address

of

providers
.
<!-- Consumer application name, used to calculate dependencies, not matching conditions, not the same as the provider -->
	<dubbo:application name="patronli" />
	<!-- Use the zookeeper registry to expose the service address, the ip+port deployed by the registry-->
	<dubbo:registry address="zookeeper://192.168.52.38:8098" />
	<!-- Generate a remote service proxy, you can use demoService like a local bean -->
	<bean id="indexAction" class="com.fuiou.consumer.Consumer" scope="prototype">
		<property name="demoService" ref="demoService"></property>
	</bean>
	<dubbo:reference id="demoService" interface="com.fuiou.provider.DemoService" />

1.2 Provider's
	<!-- provider application information for calculating dependencies -->
	<dubbo:application name="bossli" />
	<!-- Use the zookeeper registry to expose the service address -->
	<dubbo:registry address="zookeeper://192.168.52.38:8098" />
	<!-- Use the dubbo protocol to expose the service on port 20889 (define a port number that does not conflict with the existing one) -->
	<dubbo:protocol name="dubbo" port="20889" />
    <!--A business block-->
	<!-- Declare the service interface that needs to be exposed -->
	<dubbo:service interface="com.fuiou.provider.DemoService" ref="demoService" />
    <!-- Concrete implementation bean -->
	<bean id="demoService" class="com.fuiou.provider.impl.DemoServiceImpl" />

1.3: Explanation
In fact , the important thing in dubbo is the above configuration, -- declare an interface on the consumer (caller), and then declare the same interface on the provider (callee), which needs to keep the same directory as the consumer. Next You can implement this interface and return the result to the consumer
1.4 registry The location modification in the figure below is the port number of dubbo:registry. 3. Zookepper is successfully started as shown in the figure below. 1.5 Dubbo project precautions 1. Start the registry first , then start the project If the tomcat server is used, the port number should not be 8080. 4. If the following reasons occur, the points to be checked are whether the registry address of the xml configuration is correct, whether the zookepper is started or repeatedly started, and the port number is occupied or not started at all. Because the project is too large, please Private message or leave a message to ask for the projects I built (web projects and pure java projects) and zookepper


















Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326265160&siteId=291194637
Recommended