LognPoolingLib 1.3.0
dotnet add package LognPoolingLib --version 1.3.0
NuGet\Install-Package LognPoolingLib -Version 1.3.0
<PackageReference Include="LognPoolingLib" Version="1.3.0" />
<PackageVersion Include="LognPoolingLib" Version="1.3.0" />
<PackageReference Include="LognPoolingLib" />
paket add LognPoolingLib --version 1.3.0
#r "nuget: LognPoolingLib, 1.3.0"
#:package LognPoolingLib@1.3.0
#addin nuget:?package=LognPoolingLib&version=1.3.0
#tool nuget:?package=LognPoolingLib&version=1.3.0
A simple implementation of long pooling for asp.net with an example. LognPoolingLib is actually the library itself, WebApplicationTestLongPooling is an example of usage.
Usage example: Creating a client.
var url = "http://localhost:5000/loongPooling";
var key = Encoding.UTF8.GetBytes("1111111111111111");
var iv = Encoding.UTF8.GetBytes("1111111111111111");
var client = new LongPoolingClient(key, iv);
The client is authorized using the request header. It is recommended to put an encrypted token string in this header. The example shows the simplest authorization, it should not be used in a production environment.
var headers = new Dictionary<string, string>();
headers.Add("user", "user");
headers.Add("Accept", "text/message");
client.SetHeaders(headers);
Client
var url = "http://localhost:5000/loongPooling";
var key = Encoding.UTF8.GetBytes("1111111111111111");
var iv = Encoding.UTF8.GetBytes("1111111111111111");
var client = new LongPoolingClient(key, iv);
var headers = new Dictionary<string, string>();
headers.Add("user", "user");
headers.Add("Accept", "text/message");
client.SetHeaders(headers);
client.MessageDelivered += (m) =>
{
Console.WriteLine($"{m.Channel} {m.Text}");
};
client.SubscribeToChannel("channel1", (m) => Console.WriteLine($"the Channel = channel1, {m}"));
client.SubscribeToChannel("channel2", (m) => Console.WriteLine($"the Channel = channel2, {m}"));
client.SubscribeToChannel("channel3", (m) => Console.WriteLine($"the Channel = channel2, {m}"));
client.Start(url);
while (true)
{
await Task.Delay(1000);
}
Server: long pooling constroller
[Route("[controller]")]
[ApiController]
public class LoongPoolingController : ControllerBase, IDisposable
{
private readonly MessageQueuePool messageQueuePool;
UserCancellationTokenSource cancellationTokenSource;
CancellationTokenSource getCancellationTokenSource;
public LoongPoolingController(MessageQueuePool message)
{
getCancellationTokenSource = new CancellationTokenSource();
this.messageQueuePool = message;
this.messageQueuePool.AddMessageEvent += (m) =>
{
cancellationTokenSource?.Cancel(m.User);
};
}
[HttpGet]
public async IAsyncEnumerable<string> GetNew()
{
var key = Encoding.UTF8.GetBytes("1111111111111111");
var iv = Encoding.UTF8.GetBytes("1111111111111111");
var cripto = new Cripto<MessageDTO>(key, iv);
var user = HttpContext.Request.Headers["user"];
cancellationTokenSource = new UserCancellationTokenSource(user);
while (!getCancellationTokenSource.IsCancellationRequested)
{
if (this.HttpContext.RequestAborted.IsCancellationRequested)
{
getCancellationTokenSource.Cancel();
}
var count = this.messageQueuePool.Count(user);
if (count > 0)
{
var longPoolingServiceMessage = this.messageQueuePool.Dequeue(user);
var messageDTO = (MessageDTO)longPoolingServiceMessage;
var encryptObject = cripto.EncryptObject(messageDTO);
yield return encryptObject.PadRight(1024, new char());
}
else
{
try
{
await Task.Delay(10000, cancellationTokenSource.Token);
}
catch (TaskCanceledException e)
{
cancellationTokenSource = new UserCancellationTokenSource(user);
}
}
}
}
public void Dispose()
{
cancellationTokenSource.Cancel();
getCancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
getCancellationTokenSource.Dispose();
}
}
Adding a message to the queue
MessageQueuePool message;
message.Enqueue(new Message() {
Channel = "Channel1",
Text = "Text",
User = "User"
});
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.0 | 300 | 11/30/2025 |