This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Server | |
await conn.SubscribeRequestAsync("foobar", (int x) => $"Hello {x}"); | |
// Client(response: "Hello 100") | |
var response = await conn.RequestAsync<int, string>("foobar", 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Options can configure `with` operator | |
var options = NatsOptions.Default with | |
{ | |
Url = "nats://127.0.0.1:9999", | |
LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Information), | |
Serializer = new MessagePackNatsSerializer(), | |
ConnectOptions = ConnectOptions.Default with | |
{ | |
Echo = true, | |
Username = "foo", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create connection(default, connect to nats://localhost:4222) | |
await using var conn = new NatsConnection(); | |
// for subscriber. await register to NATS server(not means await complete) | |
var subscription = await conn.SubscribeAsync<Person>("foo", x => | |
{ | |
Console.WriteLine($"Received {x}"); | |
}); | |
// for publisher. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DFrameWorker : MonoBehaviour | |
{ | |
DFrameWorkerApp app; | |
[RuntimeInitializeOnLoadMethod] | |
static void Init() | |
{ | |
new GameObject("DFrame Worker", typeof(SampleOne)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DFrame.RestSdk; | |
var client = new DFrameClient("http://localhost:7312/"); | |
// start request | |
await client.ExecuteRequestAsync(new() | |
{ | |
Workload = "SampleWorkload", | |
Concurrency = 10, | |
TotalRequest = 100000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DFrame; | |
var builder = DFrameApp.CreateBuilder(7312, 7313); | |
builder.ConfigureWorker(x => | |
{ | |
x.IncludesDefaultHttpWorkload = true; | |
}); | |
builder.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DFrame; | |
using Microsoft.Extensions.DependencyInjection; | |
// use builder can configure services, logging, configuration, etc. | |
var builder = DFrameApp.CreateBuilder(7312, 7313); | |
builder.ConfigureServices(services => | |
{ | |
services.AddSingleton<HttpClient>(); | |
}); | |
await builder.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GrpcTest : Workload | |
{ | |
GrpcChannel? channel; | |
Greeter.GreeterClient? client; | |
public override async Task SetupAsync(WorkloadContext context) | |
{ | |
channel = GrpcChannel.ForAddress("http://localhost:5027"); | |
client = new Greeter.GreeterClient(channel); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DFrame; | |
DFrameApp.Run(7312, 7313); // WebUI:7312, WorkerListen:7313 | |
public class SampleWorkload : Workload | |
{ | |
public override async Task ExecuteAsync(WorkloadContext context) | |
{ | |
Console.WriteLine($"Hello {context.WorkloadId}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class FileComparer | |
{ | |
public static bool CompareEquals(string filePath1, string filePath2, int bufferSize = 65536) | |
{ | |
if (filePath1 == filePath2) return true; | |
var buffer1 = ArrayPool<byte>.Shared.Rent(bufferSize); | |
var buffer2 = ArrayPool<byte>.Shared.Rent(bufferSize); | |
try | |
{ |