Getting Started
The package can be found on NuGet and can be installed with the following command:
The first step is to register Channels with the DI container and configure the channel middleware pipelines.
Channel configurations are always named, allowing multiple protocol pipelines to coexist in the same application. If only a single pipeline is required, a default channel configuration can be used instead.
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 you need to configure multiple channels, use the parameterless method, which returns a builder that allows you 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 configuring the channels, add the listener services. The library provides listeners for TCP and UDP channels. When adding a listener, you can specify the channel name and the options, or you 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 );
You can use multiple listeners in the same application (with different ports), each with its own configuration.
Examples
You can find examples in the GitHub repository.