Table of Contents

Interface INatsMsg<T>

Namespace
NATS.Client.Core
Assembly
NATS.Client.Core.dll

This interface provides an optional contract when passing messages to processing methods which is usually helpful in creating test doubles in unit testing.

public interface INatsMsg<T>

Type Parameters

T

Data type of the payload

Remarks

Using this interface is optional and should not affect functionality.

There is a performance penalty when using this interface because NatsMsg<T> is a value type and boxing is required. A boxing allocation occurs when a value type is converted to the interface type. This is because the interface type is a reference type and the value type must be converted to a reference type. You should benchmark your application to determine if the interface is worth the performance penalty or makes any noticeable degradation in performance.

Properties

Connection

NATS connection this message is associated to.

Data

Serializable data object.

Error

Any errors (generally serialization errors) encountered while processing the message.

Headers

Pass additional information using name-value pairs.

ReplyTo

The reply subject that subscribers can use to send a response back to the publisher/requester.

Size

Message size in bytes.

Subject

The destination subject to publish to.

Methods

EnsureSuccess()

Throws an exception if the message contains any errors (generally serialization errors).

ReplyAsync(NatsHeaders?, string?, NatsPubOpts?, CancellationToken)

Reply with an empty message.

ReplyAsync<TReply>(NatsMsg<TReply>, INatsSerialize<TReply>?, NatsPubOpts?, CancellationToken)

Reply to this message.

ReplyAsync<TReply>(TReply, NatsHeaders?, string?, INatsSerialize<TReply>?, NatsPubOpts?, CancellationToken)

Reply to this message.