Services do not respond to stats when a serialiser is used
Closed this issue · 1 comments
Observed behavior
When registering a service using NatsJsonSerializerRegistry.Default the service throws an exception when called for stats or list:
nats micro stats
nats micro list
A review in code during Slack conversation shows the error at:
which does not explicitly set the serializer on the subscription
Expected behavior
The expectation is to respond as if the service is consuming primitive types
Server and client version
Server: 2.10.5
Client: 2.0.2
Host environment
No response
Steps to reproduce
Register a service while connecting with NatsOpts.Default will respond to nats micro ls and nats micro stats
If you register the service while connecting with:
var _SerializerRegistry = NatsJsonSerializerRegistry.Default;
var opts = NatsOpts.Default with
{
SerializerRegistry = _SerializerRegistry
};
Will throw the following exception when calling nats micro list or nats micro stats :
dbug: NATS.Client.Core.NatsSubBase[1002]
End subscription Exception
NATS.Client.Core.NatsSubBase: Debug: End subscription Exception
workaround for now:
var opts = new NatsOpts { SerializerRegistry = MyReg.Default };
class MyReg : INatsSerializerRegistry
{
public static MyReg Default { get; } = new();
public INatsSerialize<T> GetSerializer<T>() => MySer<T>.Default;
public INatsDeserialize<T> GetDeserializer<T>() => MySer<T>.Default;
}
class MySer<T> : INatsSerializer<T>
{
public static INatsSerializer<T> Default { get; } = new NatsRawSerializer<T>(new MySer<T>());
public void Serialize(IBufferWriter<byte> bufferWriter, T value) => NatsJsonSerializer<T>.Default.Serialize(bufferWriter, value);
public T? Deserialize(in ReadOnlySequence<byte> buffer) => NatsJsonSerializer<T>.Default.Deserialize(buffer);
}