Micro Framework service providers to build electricity projects - create micro-channel and Member Services

Description: I am writing this blog post for two main reasons: First, the easy access to I, II, and want to learn for the whole white micro inspection service of friends. The following mainly from Yu Shengjun , I will be refined on the basis of his steps so white can understand, please also reproduced at the time of the introduction Yu Shengjun link

1.1.  Creating a project working set

 

1.1.  Electricity supplier functional block diagram of the project

1.1.  Building project

1.1.  Construction of parent project

1.1.  Construction of a subclass

Similarly, deleting one-shop-basics project was src file

1.1.  Establishment of one-shop-basics have to subproject

Similarly create the remaining items

1.1.  2. building project

1.1.1  build eureka

1.1.1.1.  Installation yaml plug

Eclipse installation yaml plug if installed may skip this step

1.1.1.1.  Creating eureka profile application.yml

###服务端口号  建议多个服务间设定的端口号要有一定的规律,比如eureka用8100  订单服务用8200等规则
server:
  port: 8100
###eureka 基本信息配置
eureka:
  instance:
    ###注册到eurekaip地址
    hostname: 127.0.0.1
  client:
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
###因为自己是为注册中心,不需要自己注册自己
    register-with-eureka: false
###因为自己是为注册中心,不需要检索服务
    fetch-registry: false

  

1.1.1.1.  Eureka启动类:AppEureka

package com.cyb.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/*
 * Eureka 启动类
 */
@SpringBootApplication
@EnableEurekaServer
public class AppEureka {

    public static void main(String[] args) {
        SpringApplication.run(AppEureka.class, args);
    }
}

1.1.1. 构建微信接口服务

1.1.1.1. 建立实体

package com.one.weixin.entity;

import lombok.Data;

@Data
public class AppEntity {
    
    private String appId;
    private String appName;
    

    public AppEntity() {
        super();
    }

    public AppEntity(String appId, String appName) {
        super();
        this.appId = appId;
        this.appName = appName;
    }
}

1.1.1.1. 建立接口WeiXinAppService

package com.one.weixin.service;

import org.springframework.web.bind.annotation.GetMapping;

import com.one.weixin.entity.AppEntity;

/**
 * 微信服务接口
 * @author 陈远波
 *
 */
public interface WeiXinAppService {

    /**
     * 应用服务接口
     * @return
     */
    @GetMapping("/getApp")
    public AppEntity getApp();

1.1.1. 构建微信实现服务

1.1.1.1. 微信服务配置文件application.yml

###微信服务启动端口号
server:
  port: 8200
###服务名称(服务注册到eureka名称)  
spring:
    application:
        name: app-one-weixin
###服务注册到eureka地址
eureka:
  client:
    service-url:
           defaultZone: http://localhost:8100/eureka

1.1.1.1. 构建微信实现服务类WeiXinAppServiceImpl

package com.one.weixin.service.impl;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.one.weixin.entity.AppEntity;
import com.one.weixin.service.WeiXinAppService;

/**
 * 微信服务接口的实现
 * @author 陈远波
 *
 */
@RestController
public class WeiXinAppServiceImpl implements WeiXinAppService {

    @GetMapping("/getApp")
    public AppEntity getApp() {
        // TODO Auto-generated method stub
        AppEntity app= new AppEntity("appId:","appName");
        return app;
    }

}

1.1.1.1. Springboot启动类

package com.one;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;


/*
 * Eureka 启动类
 */
@SpringBootApplication
@EnableEurekaClient
public class AppWeiXin {

    public static void main(String[] args) {
        SpringApplication.run(AppWeiXin.class, args);
    }
}

1.1.1. 构建会员接口服务

1.1.1.1. 会员接口类

package com.one.member;
import com.one.weixin.entity.AppEntity;

public interface MemberService {

    /*
     * 会员服务调用微信接口
     */
    public AppEntity memberInvokeWeixin();
}

1.1.1. 构建会员实现服务

1.1.1.1. 会员服务配置文件application.yml

###会员服务启动端口号
server:
  port: 8300
###服务名称(服务注册到eureka名称)  
spring:
    application:
        name: app-one-member
###服务注册到eureka地址
eureka:
  client:
    service-url:
           defaultZone: http://localhost:8100/eureka

1.1.1.1. 会员调用微信接口的feign客户端接口

package com.one.member.feign;

import org.springframework.cloud.openfeign.FeignClient;

import com.one.weixin.service.WeiXinAppService;

@FeignClient(name="app-one-weixin")
public interface WeixinAppServiceFeign extends WeiXinAppService{

}

1.1.1.1. 会员实现类

package com.one.member.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.one.member.MemberService;
import com.one.member.feign.WeixinAppServiceFeign;
import com.one.weixin.entity.AppEntity;
import com.one.weixin.service.WeiXinAppService;

@RestController
public class MemberServiceImpl implements MemberService{

    @Autowired
    private WeixinAppServiceFeign weixinAppServiceFeign;
    
    

    @GetMapping("/memberInvokeWeixin")
    @Override
    public AppEntity memberInvokeWeixin() {
        // TODO Auto-generated method stub
        return weixinAppServiceFeign.getApp();
    }

}

1.1.1.1. 启动类

Package Penalty for com.one;
 Import org.springframework.boot.SpringApplication;
 Import org.springframework.boot.autoconfigure.SpringBootApplication;
 Import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
 Import org.springframework.cloud.openfeign.EnableFeignClients; 

@ SpringBootApplication 
@EnableEurekaClient 
@EnableFeignClients 
public  class AppMember { 

    public  static  void main (String [] args) { 
        SpringApplication.run (AppMember. class , args); 
    } 
} 

the above content is for reference only, need the source article blog can whisper to me, Park my blog address is:https://www.cnblogs.com/chenyuanbo/

Guess you like

Origin www.cnblogs.com/chenyuanbo/p/12105228.html