# Platform

MassTransit supports building, deploying, and monitoring services on a container-based platform. The platform provides a consistent hosting environment for consumers, sagas, and activities, eliminating duplicated service code (no more cut-and-pasting Program.cs). The platform Docker images can be used to deploy services to any container-based environment.

The platform image is hosted on Docker (opens new window) and is updated independent of the MassTransit package.

There are transport images as well, including RabbitMQ (opens new window) and ActiveMQ (opens new window).

A preconfigured image for scheduling messages using Quartz (opens new window) is also available. The source (opens new window) is a good example of how to build an assembly for hosting on the platform. A preconfigured SQL Server (opens new window) container is also available for development purposes.

These images can be configured to specify the transport, as well as other options.

There is also a Live-Coding Video (opens new window) showing the Twitch sample being converted to run on the platform.

To build a service using the MassTransit Platform, create a startup class that implemented the IPlatformStartup interface.

Package: MassTransit.Platform.Abstractions (opens new window)

public class OrderServicePlatformStartup :
    IPlatformStartup
{
    readonly ILogger<OrderServicePlatformStartup> _logger;

    public QuartzPlatformStartup(IConfiguration configuration, ILogger<OrderServicePlatformStartup> logger)
    {
        _logger = logger;
    }

    public void ConfigureMassTransit(IServiceCollectionConfigurator configurator, IServiceCollection services)
    {
        _logger.LogInformation("Configuring Order Service");

        configurator.AddConsumer<SubmitOrderConsumer>(typeof(SubmitOrderConsumerDefinition));
    }

    public void ConfigureBus<TEndpointConfigurator>(IBusFactoryConfigurator<TEndpointConfigurator> configurator, IServiceProvider provider)
        where TEndpointConfigurator : IReceiveEndpointConfigurator
    {
    }
}

The example adds a consumer, including a consumer definition. When the bus is started, an endpoint will be created by convention for the consumer.

# Adding Configuration

To access configuration options, such as appsettings.json or environment variables, add the configuration classes in the platform startup class.

public class OrderServicePlatformStartup :
    IPlatformStartup
{
    readonly IConfiguration _configuration;

    public QuartzPlatformStartup(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    public void ConfigureMassTransit(IServiceCollectionConfigurator configurator, IServiceCollection services)
    {
        services.Configure<OrderServiceOptions>(_configuration.GetSection("OrderService"));
    }
}