Spring Cloud +. NET Core implements MicroServices architecture

Source: Internet
Author: User

1. New Spring Boot Project

2. Add Spring-cloud-starter-eureka-server Dependency (version information required)

<!--https://mvnrepository.com/artifact/org.springframework.cloud/ Spring-cloud-starter-eureka-server-        <dependency>            <groupId> Org.springframework.cloud</groupid>            <artifactid>spring-cloud-starter-eureka-server</ artifactid>            <version>1.4.  4. Release</version>        </dependency>

3. Setting Program Properties Information

Spring.application.name=myservicehubserver.port=#强制不注册到注册服务器eureka. Client.register -with-eureka=falseEureka.client.fetch-registry=false# Registration Center Address Eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/# Expulsion downline Service, interval, 5 seconds, default is 60, recommended development and test environment configuration # Org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.evictionIntervalTimerInMseureka.server.evictionInt Ervaltimerinms=

4. Create a new. NET core Webapi and install the Pivotal.Discovery.Client NuGet package

Install-package Pivotal.Discovery.Client
 public  class   program { public  static  void  Main (string  Span style= "COLOR: #000000" >[] args) {buildwebhost (args).        Run ();  public  static  iwebhost buildwebho St (string  [] args) => WEBHOST.CREATEDEFAULTB Uilder (args). Usestartup  <startup> (). Useurls (  " http://*:5001   " ).    Build (); }
 Public classStartup { PublicStartup (iconfiguration configuration) {Configuration=configuration; }         PublicIConfiguration Configuration {Get; } //This method gets called by the runtime. Use this method to add services to the container.         Public voidconfigureservices (iservicecollection services) {services.            Adddiscoveryclient (Configuration); Services.        Addmvc (); }        //This method gets called by the runtime. Use this method to configure the HTTP request pipeline.         Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env) {if(env. Isdevelopment ()) {app.            Usedeveloperexceptionpage (); } app.            Usemvc (); App.        Usediscoveryclient (); }    }

5.appsettings.json, register service to Eureka-server

{"Logging": {    "Includescopes":false,    "LogLevel": {        "Default":"Warning"    }},"Spring": {    "Application": {        "name":"ServiceOne"    }},"Eureka": {  "Client": {    "serviceurl":"http://localhost:5000/eureka/",    "Shouldfetchregistry":false,    "Shouldregisterwitheureka":true  },    "instance": {        "Port":5001    }}}

Spring Cloud +. NET Core implements MicroServices architecture

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.