In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how .netcore uses the surging framework to publish to docker. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Demo runs in the docker of windows, and the system is win10, so you need to download Docker for Windows first. After installation, the system will restart. Then the shortcut icon of Docker for Windows can be found on the desktop. There is a small whale icon in the lower right corner.
Right-click and select Kitematic from the menu
You will be prompted to download Kitematic, download it yourself and decompress it, so that you can quickly download Kitematic to your desktop.
Open Kitematic and download the relevant images of RabbitMQ, redis and consul in the search bar, because these are prerequisites for surging to run.
Then download the surging gateway project on GitHub, and modify the Address address under Register in gatewaySettings.json, which corresponds to the ip of the consul docker image.
For more information on how to view its ip, please see the following:
Open Kitematic and click on the lower left corner, as shown in the figure:
Go to the command window and type docker container ls or docker ps-a to view docker
You can see information about the docker that is running now.
As shown in the figure:
Then check the relevant configuration of consul, and enter the containerID of the docker inspect image. For example, the id of consul is b0e98b94638c. Enter the following command: docker inspect b0e98b94638c
Show the configuration of this docker, there will be a lot of content, but the information of ip is at the end, as shown in the figure
Find out what the ip is, and then modify the consul address in the surging gateway to: "Address": "172.17.0.4 consul 8500". Other configurations are modified according to the above operations, such as finding and modifying the redis image address.
Right-click on the Surging.ApiGateway project after modifying the gateway configuration of surging. Since it has been added in my project, it is grayed out, as shown in the figure:
After creating a new docker-Compose, modify the configuration of the docker-compose.yml as follows:
Add the mapping and network mode of the external and internal ports of docker. Here we all use the bridging mode, including the previous consul, RabbitMQ and redis are all in the same mode, so that they will be under the same VLAN.
Then run the gateway as follows:
Next, create a new solution, the name of the solution is random, as long as you like it, because the time is relatively short, I simply deal with it here, if you are not clear, you can leave a message.
Create a new Service.A, and then create a new console application Service.A, Service.B, Service.C, and a new class library Service.A.Service, Service.B.Service, Service.C.Service.
Edit Service.A.csporj, Service.B.csporj, Service.C.csporj, as follows
Copy all the reference packages in it, and modify the corresponding Service respectively, that is, Service.A references Service.A.Service,Service.B and references Service.B.Service.
Service.C references Service.C.Service
Class libraries Service.A.Service, Service.B.Service, and Service.C.Service all refer to
As shown in the figure:
Since the code is known in many places, I will only say Service.A, and Service.A.Service
Add a new Configs folder to Service.A, and add the following log4net.config,log4net.config code:
Then add cacheSettings.json, where the value of value under Map:Properties is redis address
{"CachingSettings": [{"Id": "ddlCache", "Class": "Surging.Core.Caching.RedisCache.RedisContext,Surging.Core.Caching", "Properties": [{"Name": "appRuleFile", "Ref": "rule"}, {"Name": "dataContextPool", "Ref": "ddls_sample", "Maps": [{"Name": "Redis" "Properties": [{"value": "172.17.0.2 Name 6379 MemoryCache]}, {" Name ":" defaultExpireTime "," value ":" 120 "}, {" Name ":" connectTimeout "," Value ":" 120 "} {"Name": "minSize", "Value": "1"}, {"Name": "maxSize", "Value": "10"}]}
Add eventBusSettings.json, where EventBusConnection corresponds to the address of RabbitMQ docker
{"EventBusConnection": "172.17.0.3", "EventBusUserName": "guest", "EventBusPassword": "guest"}
The code for Program.cs is as follows
Using Autofac;using Surging.Core.Codec.MessagePack;using Surging.Core.Consul;using Surging.Core.Consul.Configurations;using Surging.Core.CPlatform;using Surging.Core.CPlatform.Utilities;using Surging.Core.DotNetty;using Surging.Core.EventBusRabbitMQ;using Surging.Core.Log4net;using Surging.Core.ProxyGenerator;using Surging.Core.ServiceHosting;using Surging.Core.ServiceHosting.Internal.Implementation;using System;using System.Text;namespace Service.A {class Program {static void Main (string [] args) {NewMethod () } private static void NewMethod () {Encoding.RegisterProvider (CodePagesEncodingProvider.Instance); var host = new ServiceHostBuilder () .RegisterServices (builder = > {builder.AddMicroService (option = > {option.AddServiceRuntime (); option.AddRelateService (); / / option.UseZooKeeperManager (new ConfigInfo ("127.0.0.1 CodePagesEncodingProvider.Instance 2181")); option.UseConsulManager (new ConfigInfo ("172.17.0.48Ze500")); option.UseDotNettyTransport () Option.UseRabbitMQTransport (); option.AddRabbitMQAdapt (); / / option.UseProtoBufferCodec (); option.UseMessagePackCodec (); builder.Register (p = > new CPlatformContainer (ServiceLocator.Current));}) }) .SubscribeAt () .UseLog4net ("Configs/log4net.config") / / .UseServer ("127.0.0.1", 98) / / .UseServer ("127.0.0.1", 98, "true") / / automatically generate Token / / .UseServer ("127.0.0.1", 98, "123456789") / / fixed password Token .UseServer (options = > {options.Ip = "172.17.0.6") Options.Port = 9990; options.Token = "True"; options.ExecutionTimeoutInMilliseconds = 30000; options.MaxConcurrentRequests = 200; options.NotRelatedAssemblyFiles = "Centa.Agency.Application.DTO\\ w* | StackExchange.Redis\\ w*";}) .UseProxy () .UseStartup () .build (); using (host.Run ()) {Console.WriteLine ($"server started successfully, {DateTime.Now}"). ;}
New Startup.cs
Using Autofac;using Autofac.Extensions.DependencyInjection;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using Surging.Core.Caching.Configurations;using Surging.Core.CPlatform.Utilities;using Surging.Core.EventBusRabbitMQ.Configurations;using System;namespace Service.A {public class Startup {public Startup () {var config = new ConfigurationBuilder () .SetBasePath (AppContext.BaseDirectory); ConfigureEventBus (config); / / ConfigureCache (config);} public IContainer ConfigureServices (ContainerBuilder builder) {var services = new ServiceCollection () ConfigureLogging (services); builder.Populate (services); ServiceLocator.Current = builder.Build (); return ServiceLocator.Current;} public void Configure (IContainer app) {app.Resolve () .AddConsole ((c, l) = > (int) l > = 3);} # region private method / configure log service / private void ConfigureLogging (IServiceCollection services) {services.AddLogging () } private static void ConfigureEventBus (IConfigurationBuilder build) {build .AddEventBusFile ("eventBusSettings.json", optional: false);} / configure caching service / private void ConfigureCache (IConfigurationBuilder build) {build .AddCacheFile ("cacheSettings.json", optional: false);} # endregion}}
Add AService.cs under Service.A.Service class library
Using Surging.Core.ProxyGenerator;using System;using System.Collections.Generic;using System.Text;using System.Threading.Tasks;namespace Service.A.Service {public class AService:ProxyServiceBase,IAService {public Task SayHello (string name) {return Task.FromResult ($"{name} say: hello");}
New IAService.cs
Using Surging.Core.CPlatform.Ioc;using Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes;using System;using System.Collections.Generic;using System.Text;using System.Threading.Tasks;namespace Service.A.Service {[ServiceBundle ("api/ {Service}")] public interface IAService: IServiceKey {Task SayHello (string name);}}
Other class libraries and services are basically the same as the above code, so I won't repeat them here. If you are not clear, you can leave a message.
After all the code has been processed, right-click on the Service.A, Service.B, and Service.C projects to add the docker support file, and then generate the following file
Modify the docker-compose.yml in it
Version:'3' services: service.a: image: servicea ports:-"127.0.0.1 servicea ports 9990" network_mode: "bridge" build: context:. Dockerfile: Service.A/Dockerfile service.b: image: serviceb ports:-"127.0.0.1 serviceb ports 9991 network_mode:" bridge "build: context:. Dockerfile: Service.B/Dockerfile service.c: image: servicec ports:-"127.0.0.1 servicec ports 9992 network_mode:" bridge "build: context:. Dockerfile: Service.C/Dockerfile webapplication1: image: webapplication1 build: context:. Dockerfile:.. / WebApplication1/Dockerfile
Then select docker to run it.
Finally, visit the surging gateway to see the effect.
This is the end of the article on ".netcore how to publish to docker using the surging framework". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.