-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEmailMessageHandler.cs
More file actions
71 lines (61 loc) · 2.36 KB
/
EmailMessageHandler.cs
File metadata and controls
71 lines (61 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using CloudNimble.SimpleMessageBus.Core;
using SimpleMessageBus.Samples.Core;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SimpleMessageBus.Samples.OnPrem
{
/// <summary>
/// An example handler that shows how to process <see cref="IMessage">IMessages</see> coming off the queue that require email notifications.
/// </summary>
public class EmailMessageHandler : IMessageHandler
{
/// <summary>
/// Specifies which <see cref="IMessage"/> types are handled by this <see cref="IMessageHandler"/>.
/// </summary>
/// <returns>An <see cref="IEnumerable{Type}"/> containing all of the <see cref="IMessage"/> types this <see cref="IMessageHandler"/> supports.</returns>
public IEnumerable<Type> GetHandledMessageTypes()
{
yield return typeof(NewUserMessage);
}
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="exception"></param>
/// <returns></returns>
public Task OnErrorAsync(IMessage message, Exception exception) => throw new NotImplementedException();
/// <summary>
///
/// </summary>
/// <param name="messageEnvelope"></param>
/// <returns></returns>
public async Task OnNextAsync(MessageEnvelope messageEnvelope)
{
var result = false;
var messageType = Type.GetType(messageEnvelope.MessageType);
switch (messageType)
{
case Type newUserMessage when newUserMessage == typeof(NewUserMessage):
result = await SendNewUserEmailAsync(messageEnvelope.GetMessage<NewUserMessage>());
break;
}
//RWM: Throw an exception to get the message tossed in the poison queue.
if (!result)
{
throw new Exception("Message processing failed.");
}
}
/// <summary>
///
/// </summary>
/// <param name="newUserMessage"></param>
/// <returns></returns>
internal async Task<bool> SendNewUserEmailAsync(NewUserMessage newUserMessage)
{
//TODO: Send email here.
Console.WriteLine("The message has been processed.");
return await Task.FromResult(true);
}
}
}