Overview
In Silky, a Host is the process container that starts the application, initializes modules, and provides external communication capabilities. Silky offers several host types based on different deployment scenarios.
Host Types
GeneralHost — RPC-Only Service
A pure RPC microservice that does not expose external HTTP endpoints. Used for backend business services called only by other services via RPC.
// Program.cs
await Host.CreateDefaultBuilder(args)
.ConfigureSilkyGeneralHostDefaults<OrderHostModule>()
.Build()
.RunAsync();
Module reference:
<PackageReference Include="Silky.Agent.Host" Version="3.9.2" />
Characteristics:
- Exposes only the DotNetty TCP RPC port
- No HTTP middleware pipeline
- Lower resource footprint
- Ideal for CPU-intensive, pure backend services
WebHost — RPC + HTTP Service
A service that exposes both RPC (for service-to-service calls) and an HTTP server (for internal/partial external access, Swagger, health checks, etc.).
// Program.cs
await Host.CreateDefaultBuilder(args)
.ConfigureSilkyWebHostDefaults<OrderHostModule>(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build()
.RunAsync();
Or with WebApplication (minimal hosting):
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureSilkyGeneralHostDefaults<OrderHostModule>();
builder.Services.AddSilkyHttpCore().AddSwaggerDocuments();
var app = builder.Build();
app.MapSilkyRpcServices();
app.UseSwagger();
app.Run();
WebSocketHost — RPC + WebSocket
A service that supports WebSocket connections in addition to RPC. Use for real-time bidirectional communication (e.g., notifications, chat).
await Host.CreateDefaultBuilder(args)
.ConfigureSilkyWebSocketHostDefaults<NotificationHostModule>(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build()
.RunAsync();
Module reference:
<PackageReference Include="Silky.WebSocket" Version="3.9.2" />
GatewayHost — HTTP API Gateway
The external-facing HTTP gateway. Receives REST requests from clients and routes them to internal microservices via RPC.
await Host.CreateDefaultBuilder(args)
.ConfigureSilkyGatewayDefaults<GatewayModule>(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build()
.RunAsync();
Characteristics:
- Only exposes HTTP (no business RPC port)
- Aggregates Swagger docs from all services
- Handles JWT authentication, CORS, rate limiting
- Enables real-time service route updates via registry subscription
Port Configuration
Configure listening ports per host in appsettings.json:
{
"rpc": {
"port": 2200,
"host": "0.0.0.0"
},
"urls": "http://0.0.0.0:5000"
}
| Host Type | RPC Port | HTTP Port |
|---|---|---|
| GeneralHost | ✅ 2200 | ❌ |
| WebHost | ✅ 2200 | ✅ 5000 |
| WebSocketHost | ✅ 2200 | ✅ 5000 |
| GatewayHost | ❌ | ✅ 5000 |
