C# Multiple Subscribers on Reactive Linq Subject

SKG 66 Reputation points
2023-03-28T15:44:32.91+00:00

Hi All,

I have a requirement to process messages fast only once. Is it possible to have multiple subscribers doing the task

Currently, i am using Reactive Linq NuGet package. Please see code snippet below

TIA

 static Subject<int> subject = new Subject<int>();
 subject
                .Buffer(TimeSpan.FromMilliseconds(1), 10)
                .Subscribe((e) => {
Console.WriteLine ($"Value = {e}");
}
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,827 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 13,740 Reputation points
    2023-03-28T19:46:14.9266667+00:00

    you an use the following code block and modify

    static Subject<int> subject = new Subject<int>();
    
    // First subscriber
    subject.Subscribe((e) => {
        Console.WriteLine($"Subscriber 1 received value: {e}");
    });
    
    // Second subscriber
    subject.Subscribe((e) => {
        Console.WriteLine($"Subscriber 2 received value: {e}");
    });
    
    // Publish a value
    subject.OnNext(1);
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.