JoaoVelho
JoaoVelho

Reputation: 17

MassTransit Transactional Outbox Inheritance Events

I have a class which inherits from another class. Both of this classes are events and I consume them using MassTransit and RabbitMQ. Example:

public class EventBase {}

public class CreatedEvent : EventBase {}

public class CreatedEventConsumer : IConsumer<CreatedEvent> {}

public class EventBaseConsumer : : IConsumer<EventBase> {}

Until now when I published the CreatedEvent, on the RabbitMQ it would create 2 exchanges, 1 for each event, and bind them. So publishing the CreatedEvent would send the message for both queues, CreatedEventConsumer and EventBaseConsumer.

Now that I started using the Transactional Outbox on version 8.0.8 of MassTransit, it doesn't create the bind between the exchanges. If the bind already exists on RabbitMQ then it works normally, I receive the message on both queues, but if the bind doesn't exist then it doesn't create it and I receive it only on the CreatedEventConsumer queue.

Any ideas why this happens?

Upvotes: 0

Views: 300

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33457

The transactional outbox doesn't know about broker exchange topology, which means that for message types only published via the transactional outbox it may be necessary to tell MassTransit about those types so that they can be configured at bus startup.

To deploy the topology when the bus is started (rather than when the message is published), you can add the published message type to the bus configuration and set DeployPublishTopology to true as shown.

x.UsingRabbitMq((context, cfg) =>
{
    cfg.Publish<CreatedEvent>();

    cfg.DeployPublishTopology = true;

    // the rest 
});

This will ensure the CreatedEvent and all base/inherited type exchanges are created at startup.

You can also use AddPublishMessageTypes to add multiple message types.

Upvotes: 0

Related Questions