You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using Connected.Collections;
|
|
|
|
|
using Connected.Collections.Queues;
|
|
|
|
|
using Connected.Net;
|
|
|
|
|
using Connected.ServiceModel;
|
|
|
|
|
using Connected.Services;
|
|
|
|
|
using Ops = Common.Collections.QueueOps;
|
|
|
|
|
|
|
|
|
|
namespace Common.Collections;
|
|
|
|
|
|
|
|
|
|
internal sealed class QueueService : DistributedService, IQueueService
|
|
|
|
|
{
|
|
|
|
|
public QueueService(IContext context) : base(context)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ImmutableList<IQueueMessage>> Dequeue(DequeueArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (await IsServer())
|
|
|
|
|
return await Invoke(GetOperation<Ops.Dequeue>(), args) ?? ImmutableList<IQueueMessage>.Empty;
|
|
|
|
|
|
|
|
|
|
if (await Http.Get<List<QueueMessage>>(await ParseUrl(CollectionRoutes.Queue), args) is List<QueueMessage> result)
|
|
|
|
|
return result.ToImmutableList<IQueueMessage>();
|
|
|
|
|
|
|
|
|
|
return ImmutableList<IQueueMessage>.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Enqueue<TClient, TArgs>(TArgs args)
|
|
|
|
|
where TClient : IQueueClient<TArgs>
|
|
|
|
|
where TArgs : QueueArgs
|
|
|
|
|
{
|
|
|
|
|
if (await IsServer())
|
|
|
|
|
{
|
|
|
|
|
await Invoke(GetOperation<Ops.Enqueue<TClient>>(), args);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Http.Post<ImmutableList<IQueueMessage>>(await ParseUrl(CollectionRoutes.Queue), new object[] { typeof(TClient), args });
|
|
|
|
|
}
|
|
|
|
|
}
|