Table of Contents

Class Pipeline

Namespace
IceRpc
Assembly
IceRpc.dll

A pipeline is an invoker created from zero or more interceptors installed by calling Use(Func<IInvoker, IInvoker>), and a final invoker installed by calling Into(IInvoker). Requests using this pipeline flow through the interceptors into the final invoker. The final invoker then sends the request over a connection.

public sealed class Pipeline : IInvoker
Inheritance
Pipeline
Implements
Inherited Members
Extension Methods

Examples

The following example demonstrates how an application would typically create the pipeline and use it as the invoker for a Slice proxy or Protobuf client.

// Create a simple console logger factory and configure the log level for category IceRpc.
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
    builder
        .AddSimpleConsole()
        .AddFilter("IceRpc", LogLevel.Information));

// Create a client connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));

// Create an invocation pipeline and install the logger interceptor.
Pipeline pipeline = new Pipeline()
    .UseLogger(loggerFactory)
    .Into(connection);

Create a Slice proxy that uses the pipeline as its invoker.

// Create a Slice proxy that uses pipeline as its invocation pipeline.
var greeter = new GreeterProxy(pipeline);

Create a Protobuf client that uses the pipeline as its invoker.

// Create a Protobuf client that uses pipeline as its invocation pipeline.
var greeter = new GreeterClient(pipeline);

You can easily create your own interceptor and add it to the pipeline. The next example shows how you can create an interceptor using an InlineInvoker and add it to the pipeline with Use(Func<IInvoker, IInvoker>).

Pipeline pipeline = new Pipeline()
    .Use(next => new InlineInvoker(async (request, cancel) =>
    {
        // Add some logic before processing the request
        Console.WriteLine("before next.InvokeAsync");
        // Call the next invoker on the invocation pipeline.
        IncomingResponse response = await next.InvokeAsync(request, cancel).ConfigureAwait(false);
        Console.WriteLine($"after next.InvokerAsync; the response status code is {response.StatusCode}");
        // Add some logic after receiving the response.
        return response;
    }));

Constructors

Pipeline()

Constructs a pipeline.

public Pipeline()

Methods

Into(IInvoker)

Sets the last invoker of this pipeline. The pipeline flows into this invoker.

public Pipeline Into(IInvoker lastInvoker)

Parameters

lastInvoker IInvoker

The last invoker.

Returns

Pipeline

This pipeline.

Exceptions

InvalidOperationException

Thrown if this method is called after the first call to InvokeAsync(OutgoingRequest, CancellationToken).

InvokeAsync(OutgoingRequest, CancellationToken)

Sends an outgoing request and returns the corresponding incoming response.

public Task<IncomingResponse> InvokeAsync(OutgoingRequest request, CancellationToken cancellationToken = default)

Parameters

request OutgoingRequest

The outgoing request being sent.

cancellationToken CancellationToken

A cancellation token that receives the cancellation requests.

Returns

Task<IncomingResponse>

The corresponding IncomingResponse.

Remarks

When request is a two-way request, the returned task will not complete successfully until after the request's Payload is fully sent and the response is received from the peer. When the request is a one-way request, the returned task completes successfully with an empty response when the request's Payload is fully sent. For all requests (one-way and two-way), the sending of the request's PayloadContinuation can continue in a background task after the returned task has completed successfully.

Use(Func<IInvoker, IInvoker>)

Installs an interceptor at the end of the pipeline.

public Pipeline Use(Func<IInvoker, IInvoker> interceptor)

Parameters

interceptor Func<IInvoker, IInvoker>

The interceptor to install.

Returns

Pipeline

This pipeline.

Exceptions

InvalidOperationException

Thrown if this method is called after the first call to InvokeAsync(OutgoingRequest, CancellationToken).

See Also