I want to use Reactive Extensions to convert some messages and relay them after a short delay.
Messages look something like this:
class InMsg { int GroupId { get; set; } int Delay { get; set; } string Content { get; set; } }
The result looks something like this:
class OutMsg { int GroupId { get; set; } string Content { get; set; } OutMsg(InMsg in) { GroupId = in.GroupId; Content = Transform(in.Content);
There are several requirements:
- The length of the delay depends on the contents of the message.
- Each post has a groupid
- If a new message arrives with the same GroupId as a delayed message waiting to be transmitted, then the first message should be discarded, and only the second message will be transmitted after the new delay period.
Given the observation <InMsg> and the submit function:
IObservable<InMsg> inMsgs = ...; void Send(OutMsg o) { ...
I understand that I can use Select to perform the conversion.
void SetUp() { inMsgs.Select(i => new OutMsg(i)).Subscribe(Send); }
- How can I apply a message indicating a delay? (Please note that this may / should lead to delivery failure.)
- How to disable messages with the same GroupId?
- Can Rx solve this problem?
- Is there any other way to resolve this issue?
chillitom
source share