Faactory.Channels.Parcel
0.1.0-preview-5
See the version list below for details.
dotnet add package Faactory.Channels.Parcel --version 0.1.0-preview-5
NuGet\Install-Package Faactory.Channels.Parcel -Version 0.1.0-preview-5
<PackageReference Include="Faactory.Channels.Parcel" Version="0.1.0-preview-5" />
paket add Faactory.Channels.Parcel --version 0.1.0-preview-5
#r "nuget: Faactory.Channels.Parcel, 0.1.0-preview-5"
// Install Faactory.Channels.Parcel as a Cake Addin
#addin nuget:?package=Faactory.Channels.Parcel&version=0.1.0-preview-5&prerelease
// Install Faactory.Channels.Parcel as a Cake Tool
#tool nuget:?package=Faactory.Channels.Parcel&version=0.1.0-preview-5&prerelease
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 --prerelease
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 builder = ...;
// This adapter will decode from a byte[] and forward a Parcel.Message[]
builder.AddInputAdapter<ParcelDecoderAdapter>();
// User handler implementation to perform business logic
builder.AddInputHandler<MyMessageHandler>();
// This adapter will encode a Parcel.Message or a Parcel.Message[] into a byte[]
builder.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 builder = ...;
builder.AddMessageObserver();
With the message observer registered, we just need to tell it that we want to wait for a message with a particular identifier. Here's an example
IChannel channel = ...;
IMessageObserver observer = ...;
// for our example, we know that sending this message
// will result in a reply with the identifier 'my-reply'
await channel.WriteAsync( new Message
{
// ...
} );
// so we tell the observer just that
var replyMessage = await observer.WaitForAsync( "my-reply" );
if ( replyMessage == null )
{
// the response is null if the timeout triggers
}
This isn't enough though... Because the handling of the messages is done by our pipeline and by our handler, 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<IEnumerable<Message>>
{
private IMessageObserver observer;
public MyMessageHandler( IMessageObserver messageObserver )
{
// our observer is injected
observer = messageObserver;
}
public override Task ExecuteAsync( IChannelContext context, IEnumerable<Message> data )
{
foreach ( var message in data )
{
// ...
// let the observer know we received a message
observer.Push( message );
}
// ...
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 was computed. 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. |
-
net6.0
- Faactory.Channels.Abstractions (>= 0.1.0-preview-11)
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.