JasperFx 0.8.2


Dynamic Subscriptions


Routing Messages

Static Publishing Rules Edit on GitHub

When you publish a message using IServiceBus without explicitly setting the Uri of the desired destination, Jasper has to invoke the known message routing rules and dynamic subscriptions to figure out which locations should receive the message. Consider this code that publishes a PingMessage:

public class SendingExample
    public async Task SendPingsAndPongs(IMessageContext bus)
        // Publish a message
        await bus.Send(new PingMessage());

        // Request/Reply
        var pong = await bus.Request<PongMessage>(new PingMessage());

To route PingMessage to a channel, we can apply static message routing rules by using one of the SendMessage**** methods as shown below:

public class StaticRoutingApp : JasperRegistry
    public StaticRoutingApp(AppSettings settings)
        // Explicitly add a single message type

        // Publish any types matching the supplied filter
        // to this channel
        Publish.MessagesMatching("Message suffix", type => type.Name.EndsWith("Message"))

        // Publish any message type contained in the assembly
        // to this channel, by supplying a type contained
        // within that assembly

        // Publish any message type contained in the named
        // assembly to this channel
        Publish.MessagesFromAssembly(Assembly.Load(new AssemblyName("MyMessageLibrary")))

        // Publish any message type contained in the
        // namespace given to this channel

        // Publish any message type contained in the namespace
        // of the type to this channel

Do note that doing the message type filtering by namespace will also include child namespaces. In our own usage we try to rely on either namespace rules or by using shared message assemblies.

See also the Dynamic Subscriptions