dubbox entry

 

dubbox definition:

  dubbox and dubbo almost, dubbox maintained by Dangdang, use the http protocol and the rest coding style

 

 

Add D warehouse in maven oubbox dependent

Because: Maven does not support dubbox from the central warehouse directly import

  1. We need a dubbox-dubbox.zip package ( from github take on )

    ①  blog Instructions:

    ② https://blog.csdn.net/try_and_do/article/details/83383861

  2. unzip the file needs to be labeled jar package

    ①  command: Jar -cf file .jar file

  3. Place the jar lead into a file maven dependent libraries

    (The alibaba file (into maven repository) Replace E: \ Maven project management model \ maven_re \ com \ alibaba)

 

coding

  First, import dubbox dependent (default maven find dubbox dependent from the library)

  

  <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>dubbo</artifactId>
      <version>2.8.4</version>    </dependency>
    <! - add zk clients rely on ->
    <dependency>
      <groupId>com.github.sgroschupf</groupId>
      <artifactId>zkclient</artifactId>
      <version>0.1</version>
    </dependency>

    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <ArtifactId> resteasy-jaxrs </ artifactId>
      <version>3.0.7.Final</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <ArtifactId> resteasy client </ artifactId>
      <version>3.0.7.Final</version>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
    </dependency>

    <! - If you want to use json serialization ->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <ArtifactId> resteasy-jackson-provider </ artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <! - If you want to use xml serialization ->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <ArtifactId> resteasy-JAXB provider </ artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <! - If you want to use netty server ->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <ArtifactId> resteasy-Netty </ artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <! - If you are using Sun HTTP server ->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jdk-http</artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <! - If you are using tomcat server ->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-core</artifactId>
      <version>8.0.11</version>
    </dependency>
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-logging-juli</artifactId>
      <version>8.0.11</version>
    </dependency>
    <dependency>
      <groupId>com.esotericsoftware.kryo</groupId>
      <artifactId>kryo</artifactId>
      <version>2.24.0</version>
    </dependency>
    <dependency>
      <groupId>de.javakaffee</groupId>
      <artifactId>kryo-serializers</artifactId>
      <version>0.26</version>
    </dependency>
    <dependency>
      <groupId>de.ruedigermoeller</groupId>
      <artifactId>fst</artifactId>
      <version>1.55</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.3.3</version>
    </dependency>
    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty</artifactId>
      <version>7.0.0.pre5</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <scope>test</scope>
    </dependency>

  

1. The service provider

  service interfaces

@Path("/dosomeService")
public interface DoSomeService {

    @Path("/doSome/{userName}")
    @GET
    @Consumes({ MediaType.APPLICATION_JSON })
    public String doSome(@PathParam("userName") String userName);
}

  service realization

public class DoSomeServiceImpl implements DoSomeService {
    @Override
    public String doSome(String userName) {
        System.out.println ( "DoSomeService service doSome method dubbox released \ t" + userName);
        return "bubbox";
    }
}

  aplicationContext-provider.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">



    <! - declare the service provider ->
    <dubbo:application name="dubbox-provider"/>
    <-! Registries address ->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    <-! Dubbo service port ->
    <dubbo:protocol name="rest" port="8081"/>


    <! - Registration Services ->
    <dubbo:service interface="com.dubbo.service.DoSomeService" ref="doSomeService"/>
    <bean id="doSomeService" class="com.dubbo.service.impl.DoSomeServiceImpl"/>

</beans>

    TestApp

public class AppTest 
{
    public static void main(String[] args) throws IOException {
        // load configuration files: configuration file to be registered by SPring Dubbo service center to register them
        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext-provider.xml");
        System.out.println ( "dubbox service has been released !!!!!");
        // blocked
        System.in.read();
    }
}

  

2. Consumers

    applicationContext-consumer.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">



    <! - declare the service provider ->
    <dubbo:application name="dubbox-consumer"/>
    <-! Registries address ->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>

    <! - Consumer Services ->
    <dubbo:reference interface="com.dubbo.service.doSomeService" id="doSomeService"/>





</beans>

    test controll

public class testControll {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-consumer.xml");
        doSomeService doSomeService = (doSomeService)ctx.getBean("doSomeService");
        doSomeService.doSome ( "John Doe");
    }
}

  

 

Guess you like

Origin www.cnblogs.com/liu13-B/p/12012572.html