Learn Dubbo (v): Executable jar for building Dubbo services using MAVEN

Source: Internet
Author: User

How the Dubbo service works

1. Run with servlet container (TOMCAT)-----Not available

Cons: Increased complexity (port, management)

Wasting Resources (memory)

2, self-built Main method class to run (Spring container)-----Not recommended (local debugging available)

Cons: The advanced features provided by Dubbo itself are useless

Writing startup classes yourself can be flawed

3. Use the Main method class provided by the Dubbo Framework to run (Spring container)-----recommended

Advantages: Provided by the framework itself (Com.alibaba.dubbo.container.Main)

Graceful shutdown Possible (Shutdownhook)


Graceful shutdown

1. Introduction


Dubbo is graceful shutdown through the shutdownhook of the JDK, so if the user uses the "kill-9 pid" and other forced shutdown instructions, it will not perform graceful shutdown, only through the "kill PID" will be executed.


Principle:

    • Service Provider

      • When it stops, it is marked as not receiving new requests, and the new request comes up with a direct error, allowing the client to retry other machines.

      • It then detects if the thread in the thread pool is running, and if so, waits for all threads to complete, forcing it to close unless it times out.

    • Service Consumer

      • When stopped, no new call requests are initiated, and all new calls are error-on-client.

      • Then, detects that there are no requested responses that are not returned, waits for the response to return, and forces the shutdown unless it times out.


Set graceful downtime timeout, the default timeout time isTenSeconds: (Force off if timeout)
<dubbo:application ...> <dubbo:parameter key= "shutdown.timeout" value= "60000"/> <!--units Ms--></d Ubbo:application>
If the Shutdownhook cannot take effect, you can call it yourself:
Protocolconfig.destroyall (); Note: This method

1. Automatically load all spring configurations in the Meta-inf/spring directory.

2, Configuration: (with the Java command-d parameter or dubbo.properties)

      • Dubbo.spring.config=classpath*:meta-inf/spring/*.xml----Configuring the Spring Configuration load location


2, pom.xml in Build

<build>    <!--  Build jar package name  -->    <finalname >edu-service-user</finalName>    <resources><!--  Put src/main/ XML and properties files in resources are put into classes -->        <resource >    <targetPath>${project.build.directory}/classes</targetPath>     <directory>src/main/resources</directory>    <filtering >true</filtering>    <includes>         <include>**/*.xml</include><include>**/*.properties</include>     </includes>        </resource>         <!--  Combined Com.alibaba.dubbo.container.Main (for automatic loading meta-inf/ All spring configurations under the spring directory) &NBSP;--&GT;&NBSP;&NBSP;&NBSP;&Nbsp;    <resource>             <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>     <directory>src/main/resources/spring</directory>    <filtering >true</filtering>    <includes>         <include>spring-context.xml</include>    </includes>         </resource>    </resources>     <pluginManagement><plugins>    <!--  The Resolve Maven plugin performs a series of lifecycle-induced conflicts within Eclipse  -->    <plugin>         <groupid>org.eclipse.m2e</groupid><artifactid>lifecycle-mapping</ Artifactid><version>1.0.0</version><configuration>    <lifecyclemappingmetadata><pluginexecutions>     <pluginExecution><pluginExecutionFilter>    <groupId> org.apache.maven.plugins</groupid>    <artifactid>maven-dependency-plugin</ artifactid>    <versionrange>[2.0,) </versionRange>     <goals><goal>copy-dependencies</goal>    </goals></ Pluginexecutionfilter><action>        <ignore /> </action>    </pluginExecution></pluginExecutions>     </lifecyclemappingmetadata></configuration>    </plugin></ plugins>    </pluginmanagement>    <plugins><!--   Package jar file, configure the manifest file, add the Lib package jar dependencies --><plugin>    <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-jar-plugin</artifactId>    < configuration><classesdirectory>target/classes/</classesdirectory><archive>     <manifest><mainClass>com.alibaba.dubbo.container.Main</mainClass><!--   manifest when packing. MF file does not record timestamp version  --><useUniqueVersions>false</useUniqueVersions>    < addclasspath>true</addclasspath>    <classpathprefix>lib/</ Classpathprefix>    </manifest>    <manifestentries> <Class-Path>.</Class-Path>    </manifestEntries></archive>     </configuration></plugin><plugin>    <groupId> Org.apache.maven.plugins</groupid>    <artifactid>maven-dependency-plugin</artifactid>     <executions><execution>    <id>copy-dependencies</id>     <phase>package</phase>    <goals><goal> Copy-dependencies</goal>    </goals>    <configuration ><type>jar</type><includeTypes>jar</includeTypes><useUniqueVersions>false< /useuniqueversions><outputdirectory>    ${project.build.directory}/lib</ outputdirectory>    </configuration>                 </execution>    </ Executions></plugin>    </plugins></build>

Attention:

In Spring-context.xml:

<import resource= "Classpath:spring/dubbo-provider.xml"/>



This article is from "I Love Big gold" blog, please be sure to keep this source http://1754966750.blog.51cto.com/7455444/1902586

Learn Dubbo (v): Executable jar for building Dubbo services using MAVEN

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.