Skip to content

Getting Started

Note

This applies to the latest version of the library. If you are still using version 0.x, please refer to the migration guide.

The package can be found on NuGet and can be installed with the following command:

dotnet add package Faactory.Channels

The first step is to register with the DI container and configure the channels. These (channel) configurations are always named, which means that we can have multiple channel configurations for different purposes. Nonetheless, if we only need one channel pipeline, we can do it all at once by configuring a default channel.

IServiceCollection services = ...;

// register Channels middleware and configure the default channel
services.AddChannels( channel =>
{
    // set up input pipeline
    channel.AddInputAdapter<ExampleAdapter>()
        .AddInputHandler<ExampleHandler>();

    // set up output pipeline
    channel.AddOutputAdapter<ExampleAdapter>();
} );

If we need to configure multiple channels, we use the parameterless method, which returns a builder that allows us to configure multiple named channels.

IServiceCollection services = ...;

services.AddChannels()
    .Add( "channel1", channel =>
    {
        // set up input pipeline
        channel.AddInputAdapter<ExampleAdapter>()
            .AddInputHandler<ExampleHandler1>();

        // set up output pipeline
        channel.AddOutputAdapter<ExampleAdapter>();
    } )
    .Add( "channel2", channel =>
    {
        // set up input pipeline
        channel.AddInputAdapter<ExampleAdapter>()
            .AddInputHandler<ExampleHandler2>();

        // set up output pipeline
        channel.AddOutputAdapter<ExampleAdapter>();
    } );

After the channels are configured, we need to add the listener services. The library provides listeners for TCP and UDP channels. When adding a listener, we can specify the channel name and the options, or we can use the default channel configuration.

IServiceCollection services = ...;

// TCP listener with *default* channel configuration
services.AddTcpChannelListener( 8080 );

// TCP listener with *named* channel configuration
// services.AddTcpChannelListener( "channel1", 8080 );

// UDP listener with *default* channel configuration
// services.AddUdpChannelListener( 7701 );

We can use multiple listeners in the same application (with different ports), each with its own configuration.

Examples

You'll be able to find some examples in the GitHub repository.