扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
首先,我们在创建投放系统之前,先看一下我们的工程结构:
专注于为中小企业提供成都网站设计、网站制作、外贸营销网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业右玉免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
mscx-ad-sponsor
就是我们的广告投放系统。如上结构,我们需要首先创建一个Parent Project mscx-ad
来编写父项目的pom,来管理我们的统一依赖信息。
4.0.0
pom
mscx-ad-discovery
mscx-ad-zuul
mscx-ad-gateway
mscx-ad-discovery-nacos
mscx-ad-common
mscx-ad-db
mscx-ad-sponsor
mscx-ad-search
mscx-ad-feign-sdk
org.springframework.boot
spring-boot-starter-parent
2.1.5.RELEASE
com.sxzhongf
mscx-ad
1.0-SNAPSHOT
分布式广告系统
基于Spring Cloud Alibaba 实现的分布式广告系统
1.8
Greenwich.SR2
org.projectlombok
lombok
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false
alibaba-milestones
ali Milestones
http://maven.aliyun.com/nexus/content/groups/public/
false
org.springframework.boot
spring-boot-maven-plugin
Eureka Server (提供服务的注册和发现)
Eureka Client
创建project mscx-ad-discovery
, 然后使用SpringBoot项目的三部曲(加依赖,加注解,改配置)
spring-cloud-starter-eureka-server
mscx-ad
com.sxzhongf
1.0-SNAPSHOT
../pom.xml
4.0.0
jar
com.sxzhongf
mscx-ad-discovery
1.0-SNAPSHOT
服务发现组件
先使用eureka实现,后续会使用nacos替换掉
org.springframework.cloud
spring-cloud-starter-eureka-server
1.2.7.RELEASE
org.springframework.boot
spring-boot-maven-plugin
@EnableEurekaServer
)@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class, args);
}
}
spring:
application:
name: ad-discovery-server
server:
port: 8888
eureka:
instance:
hostname: localhost #单机版
client:
fetch-registry: false #是否从eureka server获取注册信息
register-with-eureka: false #注册自己到eureka
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
测试的时候,需要修改hosts文件
zhangpandeMacBook-Pro:etc zhangpan$ cat hosts
##
...
##
127.0.0.1 localhost
127.0.0.1 server1
127.0.0.1 server2
127.0.0.1 server3
::1 localhost
然后修改application.yml
spring:
application:
name: ad-discovery
profiles: server1
server:
port: 7777
eureka:
instance:
hostname: server1
prefer-ip-address: false
client:
service-url:
defaultZone: http://server2:8888/eureka/,http://server3:9999/eureka/
---
spring:
application:
name: ad-discovery
profiles: server2
server:
port: 8888
eureka:
instance:
hostname: server2
prefer-ip-address: false
client:
service-url:
defaultZone: http://server1:7777/eureka/,http://server3:9999/eureka/
---
spring:
application:
name: ad-discovery
profiles: server3
server:
port: 9999
eureka:
instance:
hostname: server3
prefer-ip-address: false
client:
service-url:
defaultZone: http://server2:8888/eureka/,http://server1:7777/eureka/
启动集群测试:
java -jar mscx-ad-discovery.jar --spring.profiles.active=server1
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流