Class MessageBrokerPublisher
- Namespace
- LfrlAnvil.MessageBroker.Client
- Assembly
- LfrlAnvil.MessageBroker.Client.dll
Represents a message broker listener, which allows the client to publish messages to the related channel.
public sealed class MessageBrokerPublisher
- Inheritance
-
MessageBrokerPublisher
- Inherited Members
Properties
ChannelId
Unique id of the channel to which this publisher is related.
public int ChannelId { get; }
Property Value
ChannelName
Unique name of the channel to which this publisher is related.
public string ChannelName { get; }
Property Value
Client
MessageBrokerClient instance that owns this publisher.
public MessageBrokerClient Client { get; }
Property Value
IsEphemeral
Specifies whether the publisher is ephemeral.
public bool IsEphemeral { get; }
Property Value
Remarks
Ephemeral publishers will be removed by the server when client disconnects.
State
Current publisher's state.
public MessageBrokerPublisherState State { get; }
Property Value
Remarks
See MessageBrokerPublisherState for more information.
StreamId
Unique id of the stream to which this publisher is pushing messages.
public int StreamId { get; }
Property Value
StreamName
Unique name of the stream to which this publisher is pushing messages.
public string StreamName { get; }
Property Value
Methods
GetPushContext(MemorySize?)
Acquires a MessageBrokerPushContext instance which gives access to the internal memory pool and allows to push a message to the bound channel.
public MessageBrokerPushContext GetPushContext(MemorySize? minCapacity = null)
Parameters
minCapacityMemorySize?Specifies minimum initial capacity of the allocated memory buffer. Equal to null by default, which will cause the minimum of 1KB to be used.
Returns
- MessageBrokerPushContext
Pooled MessageBrokerPushContext instance.
Exceptions
- MessageBrokerClientDisposedException
When client has already been disposed.
PushAsync(ReadOnlyMemory<byte>, IEnumerable<MessageBrokerClientRoutingTarget>?, bool)
Pushes a message to the bound channel.
public ValueTask<Result<MessageBrokerPushResult>> PushAsync(ReadOnlyMemory<byte> data, IEnumerable<MessageBrokerClientRoutingTarget>? targets = null, bool confirm = true)
Parameters
dataReadOnlyMemory<byte>Message to push.
targetsIEnumerable<MessageBrokerClientRoutingTarget>Optional collection of explicit routing targets. Equal to null by default.
confirmboolSpecifies whether the server should send confirmation that it received the message. Equal to true by default.
Returns
- ValueTask<Result<MessageBrokerPushResult>>
A task that represents the operation, which returns a Result<T> instance, with underlying MessageBrokerPushResult instance.
Remarks
Unexpected errors encountered during pushing will cause the client to be automatically disposed. Returned Result<T> will only be valid when either the message has been successfully enqueued on the server side, or the publisher is already locally unbound from the channel, which will cancel the request to the server.
Exceptions
- MessageBrokerClientDisposedException
When client has already been disposed.
- ArgumentOutOfRangeException
When one of routing
targetscontains client id that is less than or equal to 0 or when one of routingtargetscontains client name whose length is less than 1 or greater than 512.- InvalidOperationException
When routing target count limit of 32767 has been exceeded.
ToString()
Returns a string representation of this MessageBrokerPublisher instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
UnbindAsync()
Attempts to unbind this publisher from the channel.
public ValueTask<Result<MessageBrokerUnbindPublisherResult>> UnbindAsync()
Returns
- ValueTask<Result<MessageBrokerUnbindPublisherResult>>
A task that represents the operation, which returns a Result<T> instance, with underlying MessageBrokerUnbindPublisherResult instance.
Remarks
Unexpected errors encountered during publisher unbinding will cause the client to be automatically disposed. Returned Result<T> will only be valid when either the publisher has been successfully unbound from the channel on the server side, or the publisher is already locally unbound from the channel, which will cancel the request to the server.
Exceptions
- MessageBrokerClientDisposedException
When client has already been disposed.