RazorDocs Search

Streams

Type

IRazorWireChannelAuthorizer

Defines the contract for authorizing subscription requests to RazorWire channels.

Method

CanSubscribeAsync

ValueTask<bool> CanSubscribeAsync(HttpContext context, string channel)

Determines whether the current HTTP request is permitted to subscribe to the specified channel.

Parameters

  • contextThe current HTTP context for the subscription request.
  • channelThe name of the channel to subscribe to.

Returns

true if subscription is permitted, false otherwise.

Type

DefaultRazorWireChannelAuthorizer

Provides a default implementation of IRazorWireChannelAuthorizer that permits all subscriptions.

Method

CanSubscribeAsync

ValueTask<bool> CanSubscribeAsync(HttpContext context, string channel)

Determine whether the request represented by the context may subscribe to the specified channel.

Parameters

  • contextThe HTTP context of the requesting client.
  • channelThe name of the channel to subscribe to.

Returns

`true` if subscription is allowed, `false` otherwise.

Remarks

SECURITY WARNING: This default implementation allows ALL subscriptions to ANY channel. It is intended for development and prototyping only.

In a production environment, you should replace this service with an implementation that enforces your application's specific authorization rules (e.g., checking user claims or roles).

Type

InMemoryRazorWireStreamHub

Provides an in-memory implementation of IRazorWireStreamHub using Channel{T} for message distribution.

Method

PublishAsync

ValueTask PublishAsync(string channel, string message)

Publishes a message to all subscribers of the specified channel. Any subscribers that are closed or unable to accept the message are removed during the process.

Parameters

  • channelThe name of the channel to publish to.
  • messageThe message payload to deliver to subscribers.

Returns

`ValueTask.CompletedTask` on success, or a faulted `ValueTask` containing the exception if publishing failed.

Method

Subscribe

ChannelReader<string> Subscribe(string channel)

Subscribes to a named channel and returns a reader that receives messages published to that channel. The subscription uses an in-memory bounded buffer with capacity 100 that drops the oldest messages when full.

Parameters

  • channelThe name of the channel to subscribe to.

Returns

A ChannelReader{String} that yields messages published to the specified channel until the subscription is removed or the writer is completed.

Method

Unsubscribe

void Unsubscribe(string channel, ChannelReader<string> reader)

Unregisters a subscriber from the specified channel and completes its associated writer.

Parameters

  • channelThe name of the channel to remove the subscriber from.
  • readerThe subscriber's ChannelReader{String}; its paired writer will be completed and removed from channel tracking.
Type

IRazorWireStreamHub

Defines the contract for a message hub that supports pub/sub operations over named channels.

Method

PublishAsync

ValueTask PublishAsync(string channel, string message)

Publishes a string message to the specified channel.

Parameters

  • channelThe name of the channel to publish the message to.
  • messageThe message payload to publish.

Returns

A ValueTask that completes when the publish operation has finished.

Method

Subscribe

ChannelReader<string> Subscribe(string channel)

Subscribes to a named message channel and provides a reader for incoming messages.

Parameters

  • channelThe name of the channel to subscribe to.

Returns

A ChannelReader{String} that yields messages published to the specified channel; the reader completes when the subscription is removed or the hub shuts down.

Method

Unsubscribe

void Unsubscribe(string channel, ChannelReader<string> reader)

Unsubscribes the specified reader from the named channel so it no longer receives messages from that channel.

Parameters

  • channelThe name of the channel to unsubscribe from.
  • readerThe ChannelReader<string> instance to detach from the channel.