remove grpc

This commit is contained in:
Stanley Dimant
2024-04-30 11:34:42 +02:00
committed by Loporrit
parent 72df676c9d
commit 348781e5f5
12 changed files with 60 additions and 133 deletions

View File

@@ -8,9 +8,8 @@ using Prometheus;
using MareSynchronosShared.Models;
using MareSynchronosShared.Utils;
using MareSynchronosShared.Services;
using Grpc.Net.ClientFactory;
using MareSynchronosShared.Protos;
using StackExchange.Redis;
using MareSynchronos.API.Data.Enum;
namespace MareSynchronosServices.Discord;
@@ -30,21 +29,19 @@ public class MareModule : InteractionModuleBase
private readonly DiscordBotServices _botServices;
private readonly IConfigurationService<ServerConfiguration> _mareClientConfigurationService;
private readonly IConfigurationService<ServicesConfiguration> _mareServicesConfiguration;
private readonly GrpcClientFactory _grpcClientFactory;
private readonly IConnectionMultiplexer _connectionMultiplexer;
private Random random = new();
public MareModule(ILogger<MareModule> logger, IServiceProvider services, DiscordBotServices botServices,
IConfigurationService<ServerConfiguration> mareClientConfigurationService,
IConfigurationService<ServicesConfiguration> mareServicesConfiguration,
GrpcClientFactory grpcClientFactory, IConnectionMultiplexer connectionMultiplexer)
IConnectionMultiplexer connectionMultiplexer)
{
_logger = logger;
_services = services;
_botServices = botServices;
_mareClientConfigurationService = mareClientConfigurationService;
_mareServicesConfiguration = mareServicesConfiguration;
_grpcClientFactory = grpcClientFactory;
_connectionMultiplexer = connectionMultiplexer;
}
@@ -352,7 +349,7 @@ public class MareModule : InteractionModuleBase
[SlashCommand("message", "ADMIN ONLY: sends a message to clients")]
public async Task SendMessageToClients([Summary("message", "Message to send")] string message,
[Summary("severity", "Severity of the message")] MareSynchronosShared.Protos.MessageType messageType = MareSynchronosShared.Protos.MessageType.Info,
[Summary("severity", "Severity of the message")] MessageSeverity messageType = MessageSeverity.Information,
[Summary("uid", "User ID to the person to send the message to")] string? uid = null)
{
_logger.LogInformation("SlashCommand:{userId}:{Method}:{message}:{type}:{uid}", Context.Interaction.User.Id, nameof(SendMessageToClients), message, messageType, uid);
@@ -374,13 +371,10 @@ public class MareModule : InteractionModuleBase
try
{
var client = _grpcClientFactory.CreateClient<ClientMessageService.ClientMessageServiceClient>("MessageClient");
await client.SendClientMessageAsync(new ClientMessage()
{
Message = message,
Type = messageType,
Uid = uid ?? string.Empty
});
using HttpClient c = new HttpClient();
await c.PostAsJsonAsync(new Uri(_mareServicesConfiguration.GetValue<Uri>
(nameof(ServicesConfiguration.MainServerAddress)), "/msgc/sendMessage"), new ClientMessage(messageType, message, uid ?? string.Empty))
.ConfigureAwait(false);
var discordChannelForMessages = _mareServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
if (uid == null && discordChannelForMessages != null)
@@ -390,9 +384,9 @@ public class MareModule : InteractionModuleBase
{
var embedColor = messageType switch
{
MareSynchronosShared.Protos.MessageType.Info => Color.Blue,
MareSynchronosShared.Protos.MessageType.Warning => new Color(255, 255, 0),
MareSynchronosShared.Protos.MessageType.Error => Color.Red,
MessageSeverity.Information => Color.Blue,
MessageSeverity.Warning => new Color(255, 255, 0),
MessageSeverity.Error => Color.Red,
_ => Color.Blue
};

View File

@@ -22,7 +22,6 @@
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.14.1" />
<PackageReference Include="Grpc.AspNetCore" Version="2.62.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.149">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -4,8 +4,6 @@ using MareSynchronosShared.Metrics;
using Microsoft.EntityFrameworkCore;
using Prometheus;
using MareSynchronosShared.Utils;
using Grpc.Net.Client.Configuration;
using MareSynchronosShared.Protos;
using MareSynchronosShared.Services;
using StackExchange.Redis;
using MessagePack.Resolvers;
@@ -53,12 +51,6 @@ public class Startup
services.AddSingleton(m => new MareMetrics(m.GetService<ILogger<MareMetrics>>(), new List<string> { },
new List<string> { }));
var noRetryConfig = new MethodConfig
{
Names = { MethodName.Default },
RetryPolicy = null
};
var redis = mareConfig.GetValue(nameof(ServerConfiguration.RedisConnectionString), string.Empty);
var options = ConfigurationOptions.Parse(redis);
options.ClientName = "Mare";
@@ -66,18 +58,6 @@ public class Startup
ConnectionMultiplexer connectionMultiplexer = ConnectionMultiplexer.Connect(options);
services.AddSingleton<IConnectionMultiplexer>(connectionMultiplexer);
services.AddGrpcClient<ClientMessageService.ClientMessageServiceClient>("MessageClient", c =>
{
c.Address = new Uri(mareConfig.GetValue<string>(nameof(ServicesConfiguration.MainServerGrpcAddress)));
}).ConfigureChannel(c =>
{
c.ServiceConfig = new ServiceConfig { MethodConfigs = { noRetryConfig } };
c.HttpHandler = new SocketsHttpHandler()
{
EnableMultipleHttp2Connections = true
};
});
var signalRServiceBuilder = services.AddSignalR(hubOptions =>
{
hubOptions.MaximumReceiveMessageSize = long.MaxValue;