public static Props NewConsistentHashGroup( this ISenderContext senderContext, Func <object, string> messageHasher, params PID[] routees ) => new ConsistentHashGroupRouterConfig(senderContext, MurmurHash2.Hash, 100, messageHasher, routees) .Props();
public static Props NewConsistentHashGroup( this ISenderContext senderContext, Func <string, uint> hash, int replicaCount, params PID[] routees ) => new ConsistentHashGroupRouterConfig(senderContext, hash, replicaCount, null, routees).Props();
public static Props NewRandomPool( this ISenderContext senderContext, Props props, int poolSize, int?seed = null ) => new RandomPoolRouterConfig(senderContext, poolSize, props, seed).Props();
public async Task IndexSendAsync(ISenderContext senderContext) { await elasticClient.IndexAsync(new SentMessage { Message = senderContext.Message, TypeName = senderContext.Message.GetType().FullName }, i => i.Type(typeof(SentMessage))); }
public static Props NewConsistentHashPool( this ISenderContext senderContext, Props props, int poolSize, Func <string, uint>?hash = null, int replicaCount = 100, Func <object, string>?messageHasher = null ) => new ConsistentHashPoolRouterConfig(senderContext, poolSize, props, hash ?? MurmurHash2.Hash, replicaCount, messageHasher ) .Props();
public static TrackedMessage Send(ISenderContext senderContext, PID target, MessageEnvelope messageEnvelope) { if (senderContext is IContext context) { var key = context.Self.ToShortString().ToLowerInvariant(); var q = Messages.GetOrAdd(key, new FixedLenQueueEx <TrackedMessage>(QueueLen)); return(q.Add(i => new TrackedMessage(i, messageEnvelope.Message, context.Sender, TrackedMessage.Types.Direction.Out) { Target = target })); } return(null); }
internal static async Task <T> RequestAsync <T>(this ISenderContext self, PID target, object message, CancellationToken cancellationToken) { using var future = new FutureProcess(self.System); var messageEnvelope = new MessageEnvelope(message, future.Pid); self.Send(target, messageEnvelope); var result = await future.GetTask(cancellationToken); switch (result) { case DeadLetterResponse: throw new DeadLetterException(target); case null: case T: return((T)result !); default: throw new InvalidOperationException( $"Unexpected message. Was type {result.GetType()} but expected {typeof(T)}" ); } }
public static Props NewRoundRobinGroup(this ISenderContext senderContext, params PID[] routees) => new RoundRobinGroupRouterConfig(senderContext, routees).Props();
internal BroadcastRouterState(ISenderContext senderContext) => _senderContext = senderContext;
public static ISimpleScheduler ScheduleTellRepeatedly(this ISenderContext senderContext, TimeSpan delay, TimeSpan interval, PID target, object message, out CancellationTokenSource cancellationTokenSource) => new SimpleScheduler(senderContext).ScheduleSendRepeatedly(delay, interval, target, message, out cancellationTokenSource);
public static Props NewRandomGroup(this ISenderContext senderContext, int seed, params PID[] routees) => new RandomGroupRouterConfig(senderContext, seed, routees).Props();
public static Props NewConsistentHashGroup(this ISenderContext senderContext, params PID[] routees) => new ConsistentHashGroupRouterConfig(senderContext, MurmurHash2.Hash, 100, null, routees).Props();
/// <summary> /// Creates a batch context for sending a set of requests from the same thread context. /// This is useful if you have several messages which shares a cancellation scope (same cancellationToken). /// It will pre-allocate the number of futures specified and is slightly more efficient on resources than default futures. /// If more than the pre-allocated futures are used it will fall back to the default system futures. /// Dispose to release the resources used. /// </summary> /// <param name="context"></param> /// <param name="size">The number of requests to send. The batch context will pre-allocate resources for this</param> /// <param name="ct"></param> /// <returns></returns> public static BatchContext CreateBatchContext(this ISenderContext context, int size, CancellationToken ct) => new(context, size, ct);
internal static Task Sender(ISenderContext context, PID target, MessageEnvelope envelope) { target.SendUserMessage(envelope); return(Actor.Done); }
public static ISimpleScheduler ScheduleTellOnce(this ISenderContext senderContext, TimeSpan delay, PID target, object message) => new SimpleScheduler(senderContext).ScheduleSendOnce(delay, target, message);
public static Scheduler Scheduler(this ISenderContext context) => new(context);
public SimpleScheduler(ISenderContext context) => _context = context;
public PatternsController(ISenderContext context) => this.context = context;
public Task IndexSendAsync(ISenderContext senderContext) { return(Task.FromResult(0)); }
public BatchContext(ISenderContext contextContext, int batchSize, CancellationToken ct) { _context = contextContext; _ct = ct; _batchProcess = new FutureBatchProcess(contextContext.System, batchSize, ct); }
public RandomRouterState(ISenderContext senderContext, int?seed) { _random = seed.HasValue ? new Random(seed.Value) : new Random(); _senderContext = senderContext; }
public static Task <T> RequestAsync <T>(this Cluster cluster, string identity, string kind, object message, ISenderContext context, CancellationToken ct) => cluster.RequestAsync <T>(new ClusterIdentity { Identity = identity, Kind = kind }, message, context, ct) !;
public static Props NewRoundRobinPool(this ISenderContext senderContext, Props props, int poolSize) => new RoundRobinPoolRouterConfig(senderContext, poolSize, props).Props();
public SimpleScheduler() { _context = RootContext.Empty; }
internal RoundRobinRouterState(ISenderContext senderContext) => _senderContext = senderContext;
public async Task <T?> RequestAsync <T>(ClusterIdentity clusterIdentity, object message, ISenderContext context, CancellationToken ct) { var start = DateTime.UtcNow; Logger.LogDebug("Requesting {ClusterIdentity} Message {Message}", clusterIdentity, message); var i = 0; var future = new FutureProcess(context.System); PID?lastPid = null; try { while (!ct.IsCancellationRequested) { if (context.System.Shutdown.IsCancellationRequested) { return(default);
internal static Task DefaultSender(ISenderContext context, PID target, MessageEnvelope envelope) { target.Ref.SendUserMessage(target, envelope); return(Task.FromResult(0)); }
private Task DefaultSender(ISenderContext context, PID target, MessageEnvelope message) { target.SendUserMessage(message); return(Actor.Done); }
public static async Task <TResponse> Request <TResponse>(this ISenderContext context, PID pid, object message) => await context.RequestAsync <TResponse>(pid, message, 10.Seconds());
public static Props NewBroadcastGroup(this ISenderContext senderContext, params PID[] routees) => new BroadcastGroupRouterConfig(senderContext, routees).Props();