Class MessageAggregator<T>
This class is deprecated. Please use MessageGate<TStart, TEnd> instead.
Namespace: Agents.Net
Assembly: Agents.Net.dll
Syntax
public class MessageAggregator<T> : object where T : Message
Type Parameters
Name | Description |
---|---|
T | The type of the message which should be aggregated. |
Remarks
When a batch of messages is published using the OnMessages(IReadOnlyCollection<Message>) they can be united again when all last messages of the execution chain are of the same type.
-------------- --------------------- -----------------
| SplitMessage | ----> | IntermediateMessage | -----> | FinishedMessage |
-------------- --------------------- | -----------------
|
| ------------------
----> | ExceptionMessage |
------------------
Looking at the example above it would not be possible to unite the SplitMessages
again using this class as at least one IntermediateMessage
let to an ExceptionMessage
.
[Consumes(typeof(FinishedMessage))]
public class MessageAggregatorAgent : Agent
{
private readonly MessageAggregator<FinishedMessage> aggregator;
public MessageAggregatorAgent(IMessageBoard messageBoard) : base(messageBoard)
{
aggregator = new MessageAggregator<FinishedMessage>(OnAggregated);
}
private void OnAggregated(IReadOnlyCollection<FinishedMessage> aggregate)
{
//Execute your code here
}
protected override void ExecuteCore(Message messageData)
{
aggregator.Aggregate(messageData);
}
}
Constructors
| Improve this Doc View SourceMessageAggregator(Action<IReadOnlyCollection<T>>, Boolean)
Initialized a new instance of the class MessageAggregator<T>.
Declaration
public MessageAggregator(Action<IReadOnlyCollection<T>> onAggregated, bool autoTerminate = true)
Parameters
Type | Name | Description |
---|---|---|
Action<IReadOnlyCollection<T>> | onAggregated | The action which is executed when all messages were aggregated. |
Boolean | autoTerminate | If set to |
Methods
| Improve this Doc View SourceAggregate(Message)
Adds the message to this instance.
Declaration
public void Aggregate(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to add to this instance. |
TryAggregate(Message)
Tries to add the message to this instance.
Declaration
public bool TryAggregate(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to add to this instance. |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
This is useful, when the Agent consumes more than the aggregated message.