Publish/Subscribe json bug
I tried to publish and subscribe message but there is issues from newtonsoft My code:
private static IBusClient _client;
static void Main(string[] args)
{
_client = BusClientFactory.CreateDefault();
_client.SubscribeAsync<Sender>(ServeValuesAsync, x => x.WithExchange(x => x.WithName("rabit").WithType(RawRabbit.Configuration.Exchange.ExchangeType.Topic)));
}
private static Task ServeValuesAsync(Sender message, MessageContext context)
{
return _client.PublishAsync(new Sender { Message = "Test" });
}
//Publisher
public static void AddRabbitMq(this IServiceCollection services, IConfigurationSection section)
{
// RabbitMQ Configuration
var options = new RawRabbitConfiguration();
section.Bind(options);
var client = BusClientFactory.CreateDefault();
services.AddSingleton<IBusClient>(_ => client);
}
[HttpGet]
public async Task Get()
{
await busClient.PublishAsync(new Sender { Message = "Test" }, Guid.NewGuid(), x => x.WithExchange(x => x.WithName("rabit")
.WithType(RawRabbit.Configuration.Exchange.ExchangeType.Topic)));
}
I used .NET CORE 3.1 api + console app How Can i solve it? Error Message:
[17:41:09] [$4] [ERROR] [DefaultStrategy]: Error thrown in Subscriber: , Exception: Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'Rabit20.Sender, Rabit20'. Path '$type', line 1, position 44. ---> Newtonsoft.Json.JsonSerializationException: Could not load assembly 'Rabit20'. at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(StructMultiKey
2 typeNameKey) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Newtonsoft.Json.Utilities.ThreadSafeStore2.Get(TKey key) at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeByName(StructMultiKey2 typeNameKey) at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType(String assemblyName, String typeName) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName) --- End of inner exception stack trace --- at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadMetadataProperties(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue, Object& newValue, String& id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at RawRabbit.Serialization.JsonMessageSerializer.Deserialize(Byte[] bytes, Type messageType) at RawRabbit.Serialization.JsonMessageSerializer.Deserialize[T](Byte[] bytes) at RawRabbit.Operations.Subscriber1.<>c__DisplayClass11_21.<SubscribeAsync>b__2() at RawRabbit.ErrorHandling.DefaultStrategy.ExecuteAsync(Func1 messageHandler, Func2 errorHandler) [17:41:09] [$5] [ERROR] [DefaultStrategy]: Error thrown in Subscriber: , Exception: Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'Rabit20.Sender, Rabit20'. Path '$type', line 1, position 44. ---> Newtonsoft.Json.JsonSerializationException: Could not load assembly 'Rabit20'. at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(StructMultiKey2 typeNameKey) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) [17:41:09] [$4] [WARN] [DefaultStrategy]: Unable to publish message 'a333fc2f-5e3a-49ef-ae04-04a71ecf1fe1' to default error exchange.
Maybe it's a problem with .NET Core 3.1? I have different error like Method not found: 'System.String RabbitMQ.Client.DefaultBasicConsumer.get_ConsumerTag() while trying to Subscribe to the queue and another error while trying to publish message:
Attempt by method 'RawRabbit.Common.BasicPropertiesProvider.GetProperties(System.Action`1<RabbitMQ.Client.IBasicProperties>)' to access method 'RabbitMQ.Client.Framing.BasicProperties..ctor()' failed.
What version of RawRabbit are you using?