Skip to content

Commit

Permalink
Replace WebSocketApp proj with GRPC*
Browse files Browse the repository at this point in the history
Removed WebSocket project and added GRPC projects from RIM
(copy&paste).

Then removed unused stuff from GRPC* projects and specified
package versions in Directory.Packages.props.
  • Loading branch information
webwarrior-ws committed Feb 8, 2024
1 parent 33ce6fa commit a8e60f8
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 413 deletions.
4 changes: 4 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
<PackageVersion Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" />
<PackageVersion Include="TaskBuilder.fs" Version="2.1.0" />
<PackageVersion Include="FSharp.Core" Version="8.0.101" />
<PackageVersion Include="Grpc.AspNetCore" Version="2.40.0" />
<PackageVersion Include="Google.Protobuf" Version="3.18.0" />
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.40.0" />
<PackageVersion Include="Grpc.Tools" Version="2.40.0" />
</ItemGroup>
</Project>
33 changes: 23 additions & 10 deletions FX.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FX.Tests", "src\FX.Tests\FX.Tests.csproj", "{984CE32C-454B-4FF1-B388-203DFD2CEAD8}"
# Visual Studio Version 17
VisualStudioVersion = 17.8.34511.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FX.Tests", "src\FX.Tests\FX.Tests.csproj", "{984CE32C-454B-4FF1-B388-203DFD2CEAD8}"
EndProject
Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "FX.Core", "src\FX.Core\FX.Core.fsproj", "{10A328B6-51E8-40DD-B6D8-361AFAEFABFA}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FX.Core", "src\FX.Core\FX.Core.fsproj", "{10A328B6-51E8-40DD-B6D8-361AFAEFABFA}"
EndProject
Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "FX.Console", "src\FX.Console\FX.Console.fsproj", "{E741A563-9A64-49B9-8506-DEEB03DB340C}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FX.Console", "src\FX.Console\FX.Console.fsproj", "{E741A563-9A64-49B9-8506-DEEB03DB340C}"
EndProject
Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "WebSocketApp", "src\WebSocketApp\WebSocketApp.fsproj", "{E41ECB40-3CD7-473B-9B73-6BDE00BD74B4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FX.GrpcService", "src\FX.GrpcService\FX.GrpcService.csproj", "{FB1AC151-A54A-4047-BAD6-424EC4CF3F28}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FX.GrpcClient", "src\FX.GrpcClient\FX.GrpcClient.csproj", "{578D4048-175B-41BC-8EC3-FC83FF137139}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,9 +30,19 @@ Global
{E741A563-9A64-49B9-8506-DEEB03DB340C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E741A563-9A64-49B9-8506-DEEB03DB340C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E741A563-9A64-49B9-8506-DEEB03DB340C}.Release|Any CPU.Build.0 = Release|Any CPU
{E41ECB40-3CD7-473B-9B73-6BDE00BD74B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E41ECB40-3CD7-473B-9B73-6BDE00BD74B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E41ECB40-3CD7-473B-9B73-6BDE00BD74B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E41ECB40-3CD7-473B-9B73-6BDE00BD74B4}.Release|Any CPU.Build.0 = Release|Any CPU
{FB1AC151-A54A-4047-BAD6-424EC4CF3F28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB1AC151-A54A-4047-BAD6-424EC4CF3F28}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB1AC151-A54A-4047-BAD6-424EC4CF3F28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB1AC151-A54A-4047-BAD6-424EC4CF3F28}.Release|Any CPU.Build.0 = Release|Any CPU
{578D4048-175B-41BC-8EC3-FC83FF137139}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{578D4048-175B-41BC-8EC3-FC83FF137139}.Debug|Any CPU.Build.0 = Debug|Any CPU
{578D4048-175B-41BC-8EC3-FC83FF137139}.Release|Any CPU.ActiveCfg = Release|Any CPU
{578D4048-175B-41BC-8EC3-FC83FF137139}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8FD72DED-1012-4D35-8BEF-548FC4396131}
EndGlobalSection
EndGlobal
23 changes: 23 additions & 0 deletions src/FX.GrpcClient/FX.GrpcClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" />
<PackageReference Include="Grpc.Net.ClientFactory" />
<PackageReference Include="Grpc.Tools">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Protobuf Include="..\FX.GrpcService\Protos\fx.proto" GrpcServices="Client">
<Link>Protos\fx.proto</Link>
</Protobuf>
</ItemGroup>
</Project>
33 changes: 33 additions & 0 deletions src/FX.GrpcClient/Instance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

using System;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Net.Client;
using GrpcService;

namespace GrpcClient
{
public class Instance
{
private static string serverFqdn =
"localhost";

public FXGrpcService.FXGrpcServiceClient Connect()
{
var channel = GrpcChannel.ForAddress($"http://{serverFqdn}:8080");
var client = new FXGrpcService.FXGrpcServiceClient(channel);
return client;
}

public async Task<string> SendMessage(string message)
{
var client = Connect();
var reply = await client.GenericMethodAsync(
new GenericInputParam { MsgIn = "hello" }
);
Console.WriteLine($"Got response: {reply.MsgOut}");

return reply.MsgOut;
}
}
}
16 changes: 16 additions & 0 deletions src/FX.GrpcService/FX.GrpcService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Protobuf Include="Protos\fx.proto" GrpcServices="Server" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" />
</ItemGroup>
</Project>
28 changes: 28 additions & 0 deletions src/FX.GrpcService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using GrpcService;
using GrpcService.Services;

var builder = WebApplication.CreateBuilder(args);

// Additional configuration is required to successfully run gRPC on macOS.
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682

// Add services to the container.

builder.Configuration
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", false, true);

builder.Services.AddGrpc();

var app = builder.Build();


#if !DEBUG
app.Urls.Add("http://*:8080");
#endif

// Configure the HTTP request pipeline.
app.MapGrpcService<FXService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");

app.Run();
12 changes: 12 additions & 0 deletions src/FX.GrpcService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"GrpcService": {
"commandName": "Project",
"applicationUrl": "http://localhost:5178;https://localhost:7178",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true
}
}
}
23 changes: 23 additions & 0 deletions src/FX.GrpcService/Protos/fx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";

option csharp_namespace = "GrpcService";

package fx;

// The greeting service definition.
service FXGrpcService {
// Sends a greeting
rpc GenericMethod (GenericInputParam) returns (GenericOutputParam);

rpc GenericStreamOutputMethod (GenericInputParam) returns (stream GenericOutputParam);
}

// The request message containing the user's name.
message GenericInputParam {
string msgIn = 1;
}

// The response message containing the greetings.
message GenericOutputParam {
string msgOut = 1;
}
26 changes: 26 additions & 0 deletions src/FX.GrpcService/Services/FXService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Threading.Channels;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

using Grpc.Core;

namespace GrpcService.Services
{
public class FXService : FXGrpcService.FXGrpcServiceBase
{
public override async Task<GenericOutputParam> GenericMethod(GenericInputParam request, ServerCallContext context)
{
Console.WriteLine($"Received {request.MsgIn}");

return await Task.FromResult(new GenericOutputParam { MsgOut = "received " + request.MsgIn });
}

public override async Task GenericStreamOutputMethod(GenericInputParam request, IServerStreamWriter<GenericOutputParam> responseStream, ServerCallContext context)
{
Console.WriteLine(request.MsgIn);

await responseStream.WriteAsync(new GenericOutputParam { MsgOut = "ack" });
}
}
}
11 changes: 11 additions & 0 deletions src/FX.GrpcService/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"MainDB": "Server=localhost;Port=5432;Database=runintomedb;User Id=postgres;Password='localDevPassword'"
}
}
14 changes: 14 additions & 0 deletions src/FX.GrpcService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
}
}
}
112 changes: 0 additions & 112 deletions src/WebSocketApp/Middleware/WebSocketMiddleware.fs

This file was deleted.

31 changes: 0 additions & 31 deletions src/WebSocketApp/Models.fs

This file was deleted.

Loading

0 comments on commit a8e60f8

Please sign in to comment.