This file contains hidden or 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
// use this | |
public ValueTask ConnectAsync(string host, int port, CancellationToken cancellationToken) | |
public ValueTask<int> ReceiveAsync(Memory<byte> buffer, SocketFlags socketFlags, CancellationToken cancellationToken) | |
public ValueTask<int> SendAsync(ReadOnlyMemory<byte> buffer, SocketFlags socketFlags, CancellationToken cancellationToken)) | |
// don't use this | |
public Task ConnectAsync(string host, int port) | |
public Task<int> ReceiveAsync(ArraySegment<byte> buffer, SocketFlags socketFlags) | |
public Task<int> SendAsync(ArraySegment<byte> buffer, SocketFlags socketFlags) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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}"); | |
} |