Dubbo01

dubbo is essentially a jar, can be introduced by maven

 

 

Service Provider (Provider): exposed services service provider, a service provider at the start, registration services they provided to the registry.


Service consumers (Consumer): call the remote service consumer services, consumer services at startup, subscribe to the registry services they need, service consumers, providers from the list of addresses, soft load balancing algorithm based on the election a provider of call, if the call fails, then select another call.

Registry (Registry): Returns the registry service provider address list to the consumer, if there is a change, the registry will be based on long push to change the data connection to the consumer

Monitoring Center (Monitor): service consumers and providers, in memory cumulative number of calls and call time, time sent once per minute statistical data to the monitoring center

 

The dubbo introduction project, upload it to / opt path

apache-tomcat-8.5.24.tar.gz

dubbo-admin-2.6.0.war

centos7 192.168.239.139

 

unzip file unzip the file path name -c

tar -zxvf apache-tomcat-8.5.24.tar.gz

unzip  dubbo-admin-2.6.0.war -c dubbo

Configure the tomcat server.xml configuration file

server.xml directory structure 

<Server> 
    <Listener /> 
    <GlobaNamingResources> 
    </ GlobaNamingResources 
    <Service> 
        <Connector /> 
        <Engine> 
            <Logger /> 
            <Realm /> 
               <Host> 
                   <Logger /> 
                   <Context /> 
               </ Host > 
        </ Engine> 
    </ Service> 
</ Server> 



<Context> element 

that is defined by the Context interface is the most frequently used elements. each <Context element represents a single Web application running on a virtual host. a <host > may comprise a plurality of <Context> element. 
each web application has a unique representative of a corresponding web application Context .servlet container itself to create a first application is a web path:The path name of the Context is "", so the Context is the default Context of the Host docBase: root directory of the Context is webapps / mycontext /

<Context path="/dubbo" docBase="/opt/dubbo" debug="0" privileged="true" />

  

Installation zookeeper

tar -zxvf zookeeper-3.4.11

we zoo.cfg

dataDir=/opt/zookeeper-3.4.11/data

 

start up

./zkServer.sh start

./zkServer.sh status

 

dubbo into use and provide end consumer end. We need to replace two notes @Service @Reference

 

 

provider

Increase @Service com.alibaba.dubbo.config.annotation comment on the implementation class

Add application.properties

 1 # dubbo
 2 spring.dubbo.application=user-service
 3 # dubbo
 4 spring.dubbo.protocol.name=dubbo
 5 # zookeeper
 6 spring.dubbo.registry.address=192.168.239.139:2181
 7 # zookeeper
 8 spring.dubbo.registry.protocol=zookeeper
 9 # dubbo
10 spring.dubbo.base-package=com.xxx.xxx

among them

application.name service name is not provided with the other end dubbo repeat
registry.protocol is designated registry agreement
registry.address address plus port of registry number
protocol.name is distributed dubbo is fixed, do not change.
Package base-package annotations way to scan
port is the service provider for the zookeeper exposed port can not provide with other dubbo end repeat.

 

Consumer

@Autowired改成@Reference  com.alibaba.dubbo.config.annotation.Reference

application.properties

 1 spring.dubbo.application=user-web
 2 # dubbo
 3 spring.dubbo.protocol.name=dubbo
 4 # zookeeper
 5 spring.dubbo.registry.address=192.168.239.139:2181
 6 # zookeeper
 7 spring.dubbo.registry.protocol=zookeeper
 8 # dubbo
 9 spring.dubbo.base-package=com.xxx.xxx
10 spring.dubbo.consumer.timeout=600000
11 spring.dubbo.consumer.check=false

consumer.timeout is to provide access to the service end of the timeout, the default is 1000 ms

consumer.check consumer side is when you start to check whether the server can normally access. If you choose true, that when you start the consumer end, must ensure that normal service ends, otherwise the interface can not be injected.

 

Note

When performing Dubbo Dubbo communication protocols, we need to implement the serialization interface (encapsulated data objects)
Consumer Dubbo per second interval once again accessed within three seconds, a default second timeout, after three cast directly access timeout abnormal, so we in the development stage, you can set the timeout to extend the consumer, easy breakpoint debugging

# Set the timeout time
spring.dubbo.consumer.timeout = 600000
# Set the existence of inspection services
spring.dubbo.consumer.check = false

 

 

 

  

 

Guess you like

Origin www.cnblogs.com/quyangyang/p/11617320.html
01