This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdistributedeventbrokercustomization.html
72 lines (71 loc) · 3.57 KB
/
distributedeventbrokercustomization.html
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
72
---
layout: documentation
title: Distributed Event Broker
teaser: Appccelerates your local event broker until it fires over process boundaries
navigation:
- name: Tutorial
link: distributedeventbrokertutorial.html
- name: Transports
link: distributedeventbrokertransports.html
- name: Scoping & Identification
link: distributedeventbrokerscoping.html
- name: Customization
link: distributedeventbrokercustomization.html
- name: Restrictions
link: distributedeventbrokerrestrictions.html
---
<h2>Customization</h2>
<h3>Serializer</h3>
<p>If you want to use another or a custom serializer you have to inherit from <tt>DefaultDistributedFactory</tt> and override <tt>CreateEventArgsSerializer</tt>. </p>
<p>Example: </p>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[ public class CustomDistributedFactory: DefaultDistributedFactory {
public override IEventArgsSerializer CreateEventArgsSerializer()
{
return new XmlEventArgsSerializer();
}
}
]]>
</script>
<h3>Custom message</h3>
<p>If you want to extend the standard message with additional information or if your transport layer has restrictions on the message contracts, you have to inherit from <tt>DefaultDistributedFactory</tt> and override <tt>CreateMessageFactory</tt>. </p>
<p>Your message factory can extend <tt>AbstractEventMessageFactory</tt> for simple scenarios. </p>
<p>Example (taken from NServiceBus transport): </p>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[ // Custom message interface
public interface INServiceBusEventFired : IEventFired, IMessage
{
}
// Custom message implementation
public class NServiceBusEventFired : EventFired, INServiceBusEventFired
{
}
// Custom message factory
public class NServiceBusEventMessageFactory : AbstractEventMessageFactory
{
public override IEventFired CreateEventFiredMessage(Action<IEventFired> initializer)
{
return this.CreateEventFiredMessage<NServiceBusEventFired, IEventFired>(initializer);
}
}
// Custom distributed factory
public class NServiceBusDistributedFactory : DefaultDistributedFactory
{
public override IEventMessageFactory CreateMessageFactory()
{
return new NServiceBusEventMessageFactory();
}
}
]]>
</script>
<h3>Selection Strategy</h3>
<p>Selection strategies are queried when a new topic is created on the event broker where the extension is added. The default selection strategy accepts all topics. This means that all events fired on the event broker which has the extension will be published on the transport layer. </p><p>If you want to use your own convention you have to inherit from <tt>DefaultDistributedFactory</tt> and override <tt>CreateTopicSelectionStrategy</tt>. For simple scenarios the <tt>FuncTopicSelectionStrategy</tt> can be used which accepts a lambda which acts as strategy implementation. </p>
<p>Example: </p>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[ public class CustomDistributedFactory: DefaultDistributedFactory {
public override ITopicSelectionStrategy CreateTopicSelectionStrategy()
{
return new FuncTopicSelectionStrategy(topic =>
topic.Uri.StartsWith("distributed://", StringComparison.Ordinal);
}
}
]]>
</script>
<p>The strategy above would only accept event publications where the topic URI starts with distributed://. All other publications would not be published on the transport layer. </p>