Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ transports on the default port (`4062`):

| Service | Path | Description | Example Clients |
| ---------------------------------------------- | --------------------------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Slice Greeter](./src//slice/Greeter.slice) | `/VisitorCenter.Greeter` | A simple service that greets visitors | [C# Slice Secure](https://github.com/icerpc/icerpc-csharp/tree/0.5.x/examples/slice/Secure/Client)<br>[C# Slice QUIC](https://github.com/icerpc/icerpc-csharp/tree/0.5.x/examples/slice/Quic/Client) |
| [Protobuf Greeter](./src/proto/greeter.proto) | `/visitor_center.Greeter` | A simple service that greets visitors | [C# Protobuf Secure](https://github.com/icerpc/icerpc-csharp/tree/0.5.x/examples/protobuf/Secure/Client)<br>[C# Protobuf QUIC](https://github.com/icerpc/icerpc-csharp/tree/0.5.x/examples/protobuf/Quic/Client) |
| [Slice Stream](./src/slice/Generator.slice) | `/StreamExample.Generator` | A service that streams data | [C# Slice Stream](https://github.com/icerpc/icerpc-csharp/tree/0.5.x/examples/slice/Stream/Client) |
| [Protobuf Stream](./src/proto/generator.proto) | `/stream_example.Generator` | A service that streams data | [C# Protobuf Stream](https://github.com/icerpc/icerpc-csharp/tree/0.5.x/examples/protobuf/Stream/Client) |
| [Slice Greeter](./src/slice/Greeter.slice) | `/VisitorCenter.Greeter` | A simple service that greets visitors | [C# Slice Secure](https://github.com/icerpc/icerpc-csharp/tree/0.6.x/examples/slice/Secure/Client)<br>[C# Slice QUIC](https://github.com/icerpc/icerpc-csharp/tree/0.6.x/examples/slice/Quic/Client) |
| [Protobuf Greeter](./src/proto/greeter.proto) | `/visitor_center.Greeter` | A simple service that greets visitors | [C# Protobuf Secure](https://github.com/icerpc/icerpc-csharp/tree/0.6.x/examples/protobuf/Secure/Client)<br>[C# Protobuf QUIC](https://github.com/icerpc/icerpc-csharp/tree/0.6.x/examples/protobuf/Quic/Client) |
| [Slice Stream](./src/slice/Generator.slice) | `/StreamExample.Generator` | A service that streams data | [C# Slice Stream](https://github.com/icerpc/icerpc-csharp/tree/0.6.x/examples/slice/Stream/Client) |
| [Protobuf Stream](./src/proto/generator.proto) | `/stream_example.Generator` | A service that streams data | [C# Protobuf Stream](https://github.com/icerpc/icerpc-csharp/tree/0.6.x/examples/protobuf/Stream/Client) |

## Running the server using Docker

Expand All @@ -40,7 +40,7 @@ docker run \
-e LOG_LEVEL= \
-e SERVER_CERT= \
-e SERVER_KEY= \
-e USE_TLS_WITH_TCP=true icerpc/hello
icerpc/hello
```

### Docker Compose
Expand All @@ -56,7 +56,6 @@ services:
- LOG_LEVEL= #optional
- SERVER_CERT= #optional
- SERVER_KEY= #optional
- USE_TLS_WITH_TCP= #optional
volumes:
- /path/to/certificates/:/certs

Expand All @@ -71,7 +70,6 @@ The server can be configured through several environment variables:
| `LOG_LEVEL` | The [log level](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line#log-level) | `Debug` |
| `SERVER_CERT` | Path to the server certificate | `/certs/server_cert.pem` |
| `SERVER_KEY` | Path to the server private key | `/certs/server_key.pem` |
| `USE_TLS_WITH_TCP` | Configure the usage of TLS with the TCP transport | `true` |

Certificates are **required** to run the server as the QUIC transport requires TLS.

Expand Down
4 changes: 2 additions & 2 deletions src/Hello/Greeter.Protobuf/Chatbot.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) ZeroC, Inc.

using IceRpc;
using IceRpc.Features;
using IceRpc.Protobuf;

namespace Hello.Greeter.Protobuf;

/// <summary>A Chatbot is an IceRPC service that implements Protobuf service 'Greeter'.</summary>
[ProtobufService]
[Service]
internal partial class Chatbot : IGreeterService
{
public ValueTask<GreetResponse> GreetAsync(
Expand Down
4 changes: 2 additions & 2 deletions src/Hello/Greeter.Slice/Chatbot.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) ZeroC, Inc.

using IceRpc;
using IceRpc.Features;
using IceRpc.Slice;

namespace Hello.Greeter.Slice;

/// <summary>A Chatbot is an IceRPC service that implements Slice interface 'Greeter'.</summary>
[SliceService]
[Service]
internal partial class Chatbot : IGreeterService
{
public ValueTask<string> GreetAsync(string name, IFeatureCollection features, CancellationToken cancellationToken)
Expand Down
27 changes: 12 additions & 15 deletions src/Hello/Hello.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) ZeroC, Inc.

using IceRpc;
using IceRpc.Transports.Quic;
using Microsoft.Extensions.Logging;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
Expand All @@ -15,9 +14,6 @@
// The server certificate (with the full chain) file.
string serverCert = Environment.GetEnvironmentVariable("SERVER_CERT") ?? "/certs/server_cert.pem";

// Whether to use TLS with the TCP transport.
bool useTlsWithTcp = bool.Parse(Environment.GetEnvironmentVariable("USE_TLS_WITH_TCP") ?? "true");

// Load server and intermediate certificates from the server certificate file.
using var serverCertificate = X509Certificate2.CreateFromPemFile(serverCert, serverKey);

Expand All @@ -38,29 +34,30 @@
.AddFilter("IceRpc", logLevel));

// Create a router (dispatch pipeline), install two middleware and map the Slice and Protobuf Chatbot greeter services
// to their default paths.
// to their default paths, and the Slice and Protobuf RandomGenerator services to their default paths.
Router router = new Router()
.UseLogger(loggerFactory)
.UseDeadline()
.Map<Hello.Greeter.Protobuf.IGreeterService>(new Hello.Greeter.Protobuf.Chatbot())
.Map<Hello.Greeter.Slice.IGreeterService>(new Hello.Greeter.Slice.Chatbot())
.Map<Hello.Stream.Protobuf.IGeneratorService>(new Hello.Stream.Protobuf.RandomGenerator())
.Map<Hello.Stream.Slice.IGeneratorService>(new Hello.Stream.Slice.RandomGenerator());
.Map(new Hello.Greeter.Protobuf.Chatbot())
.Map(new Hello.Greeter.Slice.Chatbot())
.Map(new Hello.Stream.Protobuf.RandomGenerator())
.Map(new Hello.Stream.Slice.RandomGenerator());

// Create a server that uses the TCP transport on the default port (4062).
await using var tcpServer = new Server(
router,
useTlsWithTcp ? sslAuthenticationOptions : null,
logger: loggerFactory.CreateLogger<Server>());
serverAddressUri: new Uri("icerpc://[::0]?transport=tcp"),
serverAuthenticationOptions: sslAuthenticationOptions,
Comment thread
externl marked this conversation as resolved.
logger: loggerFactory.CreateLogger("Hello.TcpServer"));

tcpServer.Listen();

// Create a server that uses the QUIC transport on the default port (4062).
await using var quicServer = new Server(
router,
sslAuthenticationOptions,
logger: loggerFactory.CreateLogger<Server>(),
multiplexedServerTransport: new QuicServerTransport());
router,
serverAddressUri: new Uri("icerpc://[::0]?transport=quic"),
serverAuthenticationOptions: sslAuthenticationOptions,
logger: loggerFactory.CreateLogger("Hello.QuicServer"));

quicServer.Listen();

Expand Down
18 changes: 9 additions & 9 deletions src/Hello/Hello.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IceRpc.Deadline" Version="0.5.*" />
<PackageReference Include="IceRpc.Logger" Version="0.5.*" />
<PackageReference Include="IceRpc.Protobuf.Tools" Version="0.5.*" PrivateAssets="All" />
<PackageReference Include="IceRpc.Protobuf" Version="0.5.*" />
<PackageReference Include="IceRpc.Slice.Tools" Version="0.5.*" PrivateAssets="All" />
<PackageReference Include="IceRpc.Slice" Version="0.5.*" />
<PackageReference Include="IceRpc.Transports.Quic" Version="0.5.*" />
<PackageReference Include="IceRpc" Version="0.6.*" />
<PackageReference Include="IceRpc.Deadline" Version="0.6.*" />
<PackageReference Include="IceRpc.Logger" Version="0.6.*" />
<PackageReference Include="IceRpc.Protobuf.Tools" Version="0.6.*" PrivateAssets="All" />
<PackageReference Include="IceRpc.Protobuf" Version="0.6.*" />
<PackageReference Include="IceRpc.Slice.Tools" Version="0.6.*" PrivateAssets="All" />
<PackageReference Include="IceRpc.Slice" Version="0.6.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.*" />

Expand All @@ -33,8 +33,8 @@
</PackageReference>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)/../../stylecop.json" />

<SliceFile Include="../slice/*" />
<ProtoFile Include="../proto/*" />
<SliceFile Include="../slice/**/*.slice" />
<ProtoFile Include="../proto/**/*.proto" />
</ItemGroup>
<ItemDefinitionGroup>
<SliceFile>
Expand Down
4 changes: 2 additions & 2 deletions src/Hello/Stream.Protobuf/RandomGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) ZeroC, Inc.

using Google.Protobuf.WellKnownTypes;
using IceRpc;
using IceRpc.Features;
using IceRpc.Protobuf;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;

namespace Hello.Stream.Protobuf;

[ProtobufService]
[Service]
internal partial class RandomGenerator : IGeneratorService
{
public ValueTask<IAsyncEnumerable<GenerateResponse>> GenerateNumbersAsync(
Expand Down
4 changes: 2 additions & 2 deletions src/Hello/Stream.Slice/RandomGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) ZeroC, Inc.

using IceRpc;
using IceRpc.Features;
using IceRpc.Slice;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;

namespace Hello.Stream.Slice;

[SliceService]
[Service]
internal partial class RandomGenerator : IGeneratorService
{
public ValueTask<IAsyncEnumerable<int>> GenerateNumbersAsync(
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ZeroC, Inc.

[cs::namespace("Hello.Stream.Slice")]
[cs::identifier("Hello.Stream.Slice")]
module StreamExample

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to sub-dir.


/// Represents a number generator.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ZeroC, Inc.

[cs::namespace("Hello.Greeter.Slice")]
[cs::identifier("Hello.Greeter.Slice")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move the Slice files to sub-dirs like in the examples.

module VisitorCenter

/// Represents a simple greeter.
Expand Down