Compare commits
No commits in common. "016987b1017d1b8e4408a9ad5de61b404bbbf4ae" and "a2538ebbb9cdf05e3e99e37d83317af6708e2760" have entirely different histories.
016987b101
...
a2538ebbb9
|
|
@ -5,7 +5,6 @@ using Nacos.V2;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microservice.Common;
|
using Microservice.Common;
|
||||||
using Microservice.Common.Models;
|
using Microservice.Common.Models;
|
||||||
using Microservice.Common.Services;
|
|
||||||
|
|
||||||
namespace MicoService.Demo.Controllers
|
namespace MicoService.Demo.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -17,19 +16,16 @@ namespace MicoService.Demo.Controllers
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly INacosNamingService _nacosNamingService;
|
private readonly INacosNamingService _nacosNamingService;
|
||||||
private readonly IServiceClient _serviceClient;
|
private readonly IServiceClient _serviceClient;
|
||||||
private readonly IUserService _userService;
|
|
||||||
private readonly ILogger<TestController> _logger;
|
private readonly ILogger<TestController> _logger;
|
||||||
|
|
||||||
public TestController(IConfiguration configuration,
|
public TestController(IConfiguration configuration,
|
||||||
INacosNamingService nacosNamingService,
|
INacosNamingService nacosNamingService,
|
||||||
IServiceClient serviceClient,
|
IServiceClient serviceClient,
|
||||||
IUserService userService,
|
|
||||||
ILogger<TestController> logger)
|
ILogger<TestController> logger)
|
||||||
{
|
{
|
||||||
this._configuration = configuration;
|
this._configuration = configuration;
|
||||||
this._nacosNamingService = nacosNamingService;
|
this._nacosNamingService = nacosNamingService;
|
||||||
this._serviceClient = serviceClient;
|
this._serviceClient = serviceClient;
|
||||||
this._userService = userService;
|
|
||||||
this._logger = logger;
|
this._logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,8 +61,8 @@ namespace MicoService.Demo.Controllers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 使用用户服务调用用户微服务
|
// 使用微服务通讯客户端调用 Mico_Demo2222 服务
|
||||||
var result = await this._userService.GetUserInfoAsync();
|
var result = await this._serviceClient.GetAsync<ConfigInfoModel>("Mico_Demo2222", "/User/config/info");
|
||||||
var data = new ServiceCallResultModel<ConfigInfoModel>("调用成功", result);
|
var data = new ServiceCallResultModel<ConfigInfoModel>("调用成功", result);
|
||||||
return Ok(ApiResponseHelper.Success(data, "服务调用成功"));
|
return Ok(ApiResponseHelper.Success(data, "服务调用成功"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
using Nacos.AspNetCore.V2;
|
using Nacos.AspNetCore.V2;
|
||||||
using Nacos.V2.DependencyInjection;
|
using Nacos.V2.DependencyInjection;
|
||||||
using Microservice.Common;
|
using Microservice.Common;
|
||||||
using Microservice.Common.Services;
|
|
||||||
|
|
||||||
namespace MicoService.Demo
|
namespace MicoService.Demo
|
||||||
{
|
{
|
||||||
|
|
@ -32,9 +31,6 @@ namespace MicoService.Demo
|
||||||
|
|
||||||
// 注册微服务通讯客户端
|
// 注册微服务通讯客户端
|
||||||
builder.Services.AddServiceClient();
|
builder.Services.AddServiceClient();
|
||||||
|
|
||||||
// 注册用户服务
|
|
||||||
builder.Services.AddScoped<IUserService, UserService>();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microservice.Common;
|
using Microservice.Common;
|
||||||
using Microservice.Common.Models;
|
using Microservice.Common.Models;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microservice.Common.Models;
|
|
||||||
|
|
||||||
namespace Microservice.Common.Services
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 用户服务接口
|
|
||||||
/// </summary>
|
|
||||||
public interface IUserService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 获取用户配置信息
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>配置信息模型</returns>
|
|
||||||
Task<ConfigInfoModel> GetUserInfoAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microservice.Common.Models;
|
|
||||||
|
|
||||||
namespace Microservice.Common.Services
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 用户服务实现类
|
|
||||||
/// </summary>
|
|
||||||
public class UserService : IUserService
|
|
||||||
{
|
|
||||||
private readonly IServiceClient _serviceClient;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="serviceClient">微服务客户端</param>
|
|
||||||
public UserService(IServiceClient serviceClient)
|
|
||||||
{
|
|
||||||
_serviceClient = serviceClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取用户配置信息
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>配置信息模型</returns>
|
|
||||||
public async Task<ConfigInfoModel> GetUserInfoAsync()
|
|
||||||
{
|
|
||||||
// 直接使用硬编码的服务名称和路径,暂时不使用 ServiceRegistry
|
|
||||||
return await _serviceClient.GetAsync<ConfigInfoModel>("Mico_Demo2222", "/User/config/info");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue