• 【dubbo】dubbo项目基本结构及provider构建


    dubbo项目基本结构如下,分别部署于不同服务器:

    1.provider(接口API 实现)

    2.consumer(web)

    3.zookeeper

    4.DB

    provider构建

    1.api构建

    intellij中新建"maven"项目,groupId:com.dubbo.api.demo,artifactId:demo,projectName:dubbo-api-demo();

    java下添加interface:cmo.dubbo.api.demo.DemoService;

    public interface DemoService {
        String sayHello(String name);
    }

     maven-install

    2.provider 实现构建

    pom.xml中添加DUBBO-API,DUBBO,SPRING

    <dependencies>
      <dependency>
                <groupId>com.dubbo.api.demo</groupId>
                <artifactId>demo</artifactId>
                <version>1.0-SNAPSHOT</version>
      </dependency>
      
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.4.10</version>
    </dependency>
    <dependency>
        <groupId>com.github.sgroschupf</groupId>
        <artifactId>zkclient</artifactId>
        <version>0.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.16.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.16.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.2.16.RELEASE</version>
    </dependency>
    </dependencies>

    intellij中新建"maven"项目,groupId:com.dubbo.provider.demo,artifactId:demo,projectName:dubbo-provider-demo();

    java下添加class:cmo.dubbo.provider.demo.DemoServiceImpl:

    package com.dubbo.provider.demo;
    
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import com.alibaba.dubbo.rpc.RpcContext;
    import com.dubbo.api.demo.*;
    /**
     * Created by Administrator on 17-1-1.
     */
    public class DemoServiceImpl implements DemoService {
    
        public String sayHello(String name) {
            System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
            return "Hello " + name + ", response form provider: " + RpcContext.getContext().getLocalAddress();
        }
    
    }

    resources下添加dubbo配置META-INFO.spring-dubbo-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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
        <dubbo:application name="dubbo-provider-demo" ></dubbo:application>
        <dubbo:registry id="zk1" address="zookeeper://127.0.0.1:2181" protocol="zookeeper"></dubbo:registry>
        <dubbo:protocol id="mydubbo" name="dubbo" port="20886"></dubbo:protocol>
        <dubbo:provider register="zk1" protocol="mydubbo"></dubbo:provider>
        <dubbo:service interface="com.dubbo.api.demo.DemoService" ref="demoService"></dubbo:service>
        <bean id="demoService" class="com.dubbo.provider.demo.DemoServiceImpl" />
    </beans>

    启动provider,在Edit Configuration 中添加application 的启动方法,main class选择com.alibaba.dubbo.container.Main。控制台显示[2017-01-07 15:07:25] Dubbo service server started! 则表示成功启动

    
    
    
  • 相关阅读:
    dpdk学习笔记2
    <c和指针>学习笔记2之数据和语句
    dpdk数据包捕获技术笔记1
    <c++primer plus>学习笔记1之第八章函数探幽
    准备面试的那些事儿1
    tcp_fast_open的概念 作用以及实现(转)
    tcp/ip详解(转)
    Build step 'Execute Windows batch command' marked build as failure
    vmware12如何安装macOSX虚拟机
    如何将exe注册为windows服务,直接从后台运行
  • 原文地址:https://www.cnblogs.com/grape1211/p/6241163.html
Copyright © 2020-2023  润新知