-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (53 loc) · 1.46 KB
/
Program.cs
File metadata and controls
63 lines (53 loc) · 1.46 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
using MassTransit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XrmSerializer
{
internal class Program
{
private static void Main()
{
MainAsync().GetAwaiter().GetResult();
Console.ReadLine();
}
private static async Task MainAsync()
{
var bus = Bus.Factory.CreateUsingInMemory(cfg =>
{
cfg.UseXmlSerializer();
cfg.UseInMemoryScheduler();
cfg.ReceiveEndpoint("queue", c =>
{
c.Consumer<Consumer>();
});
});
await bus.StartAsync();
await bus.Publish<IMyMessage>(new { Description = "hi!" });
}
}
public interface IMyMessage
{
string Description { get; }
}
public class Consumer : IConsumer<IMyMessage>
{
public async Task Consume(ConsumeContext<IMyMessage> context)
{
if (context.Headers.TryGetHeader("MT-Redelivery-Count", out var value))
{
if (context.Headers.TryGetHeader("#text", out var val))
{
throw new Exception("this is a weird header");
}
return;
}
if (value == null)
{
await context.Redeliver(TimeSpan.FromSeconds(1));
}
}
}
}