博客
关于我
net core 微服务 快速开发框架
阅读量:425 次
发布时间:2019-03-06

本文共 3300 字,大约阅读时间需要 11 分钟。

Dym 分布式开发框架入门指南

什么是 Dym 框架

Dym 是一个支持 .NET Core 2.2 和 .NET Framework 4.6.1 的分布式开发框架。它提供了强大的工具支持,适合构建高性能和可扩展的后台服务。接下来,我们将详细介绍如何运行和配置这个框架。

安装与运行

1.1 安装 Dym Demo

首先,你需要使用 dotnet 运行 Dym 的示例项目。进入项目文件夹 dymDemo\YY.AppCenter\bin\Debug\netcoreapp2.2,运行以下命令:

dotnet AppCenter.dll

默认情况下,程序会在 6660 端口上监听。如果你看到类似下面的输出,说明程序已经成功运行:

(Assembly loaded: dym.Rpc.Center) Bootstrap v1.0.0.0

1.2 服务配置

在 dym.config 文件中,配置你的服务设置。一个基本的配置文件可能如下:

6660
120000

1.3 启动服务

接下来,进入 dymDemo\YY.Server\bin\Debug\netcoreapp2.2 文件夹,运行命令:

dotnet YY.Server.dll

默认情况下,服务会在 6659 端口上监听。如果你看到以下信息,说明服务已经成功注册到注册中心:

(Assembly loaded: dym.Rpc.Server) Bootstrap v1.0.0.0

业务开发

2.1 服务启动配置

创建一个新的 Plug 类,继承自 IPlugsConfigurationBootstrap。在 ConfigurationBootstrap 方法中,添加自定义的业务逻辑配置。

using System;using dym.EngineData;namespace dym.Plugs.YYTestService{    public class YYTestBootstrap : IPlugsConfigurationBootstrap    {        public void ConfigurationBootstrap()        {            // 服务启动时会自动调用此方法            // 可以用来加载插件配置        }        public void PreConfigurationBootstrap()        {            // Ioc 注入之前执行        }    }}

2.2 业务实现

在同一个命名空间中,添加一个新的模块类。以下是一个简单的示例:

using dym.EngineData;using System;using System.Collections.Generic;namespace dym.Plugs.YYTestService{    public class MyFirstModule : BaseModule    {        public MyFirstModule()        {        }        public ActionResult MyT()        {            var xx = RequestString("XX");            Console.WriteLine($"来自客户端的消息:{xx}");            return new ActionResult(true, new { Msg = "I from dym.Plugs.YYTestService MyFirstModule!" }, null, xx);        }    }}

客户端测试

3.1 启动测试客户端

进入 dymDemo\YY.Client\bin\Debug\netcoreapp2.2 文件夹,运行命令:

dotnet YY.Client.dll

3.2 客户端配置

在客户端代码中,配置默认参数如下:

using System;using dym.Rpc.Client;namespace YY.Client{    class Program    {        static void Main(string[] args)        {            DefaultConfigManager.SetDefaultConfiguration("YY.Client", "127.0.0.1", 6660, false);                        while (true)            {                Console.WriteLine("请输入一个消息然后回车发送到服务器:");                var inputMsg = Console.ReadLine();                                var input = new InputTest()                {                    channel = "dym.Plugs.YYTest",                    router = "MyFirst",                    method = "MyT",                    XX = $"{inputMsg}参数1"                };                                var rltStr = Connector.BrokerDns(input);                Console.WriteLine(rltStr);                                Console.WriteLine("-----------------------------------------------------------------------------");                                var inputYYTest = new InputTest()                {                    channel = "dym.Plugs.YYTest",                    router = "MySecond",                    method = "MyT",                    XX = $"{inputMsg}参数2"                };                                var rltStrYY = Connector.BrokerDns(inputYYTest);                Console.WriteLine(rltStrYY);                                goto Restart;            }        }    }        public class InputTest : InputDtoBase    {        public string XX { get; set; }    }}

3.3 调用服务

通过客户端调用服务的方法,测试分布式框架的运行效果。输出结果会显示在控制台中。

总结

通过以上步骤,你已经成功配置并运行了 Dym 分布式开发框架。接下来可以深入探索高级功能,如负载均衡、事件总线优化以及 CQRS 模式的应用。

转载地址:http://ogfuz.baihongyu.com/

你可能感兴趣的文章
phpmyadmin导出数据库出现Fatal error: Cannot 'break' 2 levels in D:\phpstudy\WWW\phpMyAdmin
查看>>
phpmyadmin数据库建表及插入
查看>>
phpnow配置
查看>>
phprpc简单使用
查看>>
phpspider中当爬虫获取数据时如何去掉广告
查看>>
phpstorm 2016.3.3 激活
查看>>
phpstorm中Xdebug的使用
查看>>
phpstorm中使用svn版本控制器
查看>>
phpstorm配置php脚本执行
查看>>
PhpStorm配置远程xdebug
查看>>
phpstudy+iis搭建php项目
查看>>
phpStudy安装教程
查看>>
phpstudy搭建网站,通过快解析端口映射外网访问
查看>>
phpunit
查看>>
PHPUnit单元测试对桩件(stub)和仿件对象(Mock)的理解
查看>>
phpweb成品网站最新版(注入、上传、写shell)
查看>>
phpWhois 项目推荐
查看>>
Redis事务详解,吃透数据库没你想的那么难
查看>>
phpwind部署问题
查看>>
PHP_CodeIgniter Github实现个人空间
查看>>