Faactory.Channels.Parcel 0.4.0

dotnet add package Faactory.Channels.Parcel --version 0.4.0
NuGet\Install-Package Faactory.Channels.Parcel -Version 0.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Faactory.Channels.Parcel" Version="0.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Faactory.Channels.Parcel --version 0.4.0
#r "nuget: Faactory.Channels.Parcel, 0.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Faactory.Channels.Parcel as a Cake Addin
#addin nuget:?package=Faactory.Channels.Parcel&version=0.4.0

// Install Faactory.Channels.Parcel as a Cake Tool
#tool nuget:?package=Faactory.Channels.Parcel&version=0.4.0

Channels - Parcel Protocol

Parcel Protocol implementation for the Channels library.

Learn more about Parcel Protocol.

Learn more about Channels;

Getting Started

Install the package from NuGet

dotnet add package Faactory.Channels.Parcel

To enable decoding or encoding of Parcel Messages on the pipeline, we just need to register the respective adapters with the channel pipeline. It is the same for server or client channels.

IChannelBuilder channel = ...;

// This adapter will decode from a byte[] and forward a Parcel.Message[]
channel.AddInputAdapter<ParcelDecoderAdapter>();

// User handler implementation to perform business logic
channel.AddInputHandler<MyMessageHandler>();

// This adapter will encode a Parcel.Message or a Parcel.Message[] into a byte[]
channel.AddOutputAdapter<ParcelEncoderAdapter>();

Observables

It is possible to write to the output channel and then wait for a specific response on the input channel. This is useful if we know that the server will reply with a Parcel Message with a specific identifier.

To make this work, we first need to register the IMessageObserver service; this will allow us to retrieve the instance through dependency injection.

IChannelBuilder channel = ...;

channel.AddMessageObserver();

With the message observer registered, we can now create an observable instance for a particular identifier. Here's an example

IChannel channel = ...;
IMessageObserver observer = ...;

/*
Sending the message below to the channel will result
in a reply with the identifier `my-reply`. Therefore,
we create an observable for that identifier.
*/
var observable = observer.CreateObservable( "my-reply" );

// send the message to the channel
await channel.WriteAsync( new Message
{
    // ...
} );

// tell the observable to wait for the reply
var replyMessage = await observable.WaitAsync();

if ( replyMessage == null )
{
    // the response is null if the timeout triggers
}

Note: The observable instance is for single use. Once the observable value is set, it is removed from the observer.

This isn't enough though... Because the handling of the messages is done by our pipeline and by our handlers, we need to tell the observer when we receive messages. For this example, we'll do it on our MyMessageHandler handler.

public class MyMessageHandler : ChannelHandler<Message>
{
    private readonly IMessageObserver observer;

    public MyMessageHandler( IMessageObserver messageObserver )
    {
        // our observer is injected
        observer = messageObserver;
    }

    public override Task ExecuteAsync( IChannelContext context, Message message )
    {
        // ...

        // let the observer know we received a message
        observer.Push( message );

        // ...
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Faactory.Channels.Parcel:

Package Downloads
Faactory.Channels.PubSub

Channels pub/sub

Influx.SDK.Consumer

Influx SDK for consumers

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.0 346 1/30/2024
0.3.1 552 12/8/2023
0.3.0 425 12/8/2023
0.2.5 399 12/8/2023
0.2.4 456 12/4/2023
0.2.2 683 6/1/2023
0.2.1 802 1/24/2023
0.2.0 779 1/23/2023
0.1.1 940 7/5/2022
0.1.0 956 4/12/2022
0.1.0-preview-5 637 4/12/2022