Table of Contents

Hooking events

Events are a way to access quickly traversing exchange without the need to create a directive.

Events are readonly and does not affect the processed exchange. If you wants to alter the exchange, you should use an existing action or create you own action.

Events provider can be access through Proxy.Writer. Fluxzy raises 3 types of events:

  • ExchangeUpdated: Occurs when an exchange is updated. You can observe the UpdateType property to know in which phase the exchange is.
  • ConnectionUpdated: Occurs when a connection is updated. A connection instance is a transport link between fluxzy and the remove server
  • ErrorUpdated: Occurs when an error is raised. HTTP errors (status 4XX or 5XX) are not considered as errors.

Here is a example that prints basic information of the event when they occured

using Fluxzy;

var fluxzySetting = FluxzySetting.CreateDefault();

// Create a new proxy instance 

await using (var proxy = new Proxy(fluxzySetting))
    proxy.Writer.ExchangeUpdated += (_, args) =>
        // Do something with the exchange
        // args.Exchange

        Console.WriteLine($"#{args.ExchangeInfo.Id:0000} {args.UpdateType}: " +
                          $"{args.ExchangeInfo.Method} {args.ExchangeInfo.FullUrl}");

    proxy.Writer.ConnectionUpdated += (_, args) =>
        // Do something with the exchange
        // args.Exchange

        Console.WriteLine($"#{args.Connection.Id:0000} New connection: " +
                          $"{args.Connection.Authority.HostName} {args.Connection.Authority.Port}");


    Console.WriteLine("Press any key to exit");