-
Notifications
You must be signed in to change notification settings - Fork 753
Could I use different types for publisher and consumer #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @WeihanLi, It is designed to use a shared component, however you can simply implement and register your own ITypeNameSerializer in both projects to change this behavior. Hope this helps? |
@zidad thanks for your help, it does help. As it's designed to use a shared component, I would move them into a shared component. |
Shared my initial type name serializer with fallback, hope it would help public sealed class FallbackTypeNameSerializer : ITypeNameSerializer
{
private readonly ITypeNameSerializer _typeNameSerializer;
public FallbackTypeNameSerializer(ITypeNameSerializer typeNameSerializer)
{
_typeNameSerializer = typeNameSerializer;
}
public bool FallbackFirst { get; set; }
public Func<Type, string> FallbackSerializer { get; set; }
public Func<string, Type> FallbackDeSerializer { get; set; }
public string Serialize(Type type)
{
if (FallbackFirst)
{
try
{
if (FallbackSerializer != null)
{
return FallbackSerializer.Invoke(type);
}
}
catch
{
// ignore
}
return _typeNameSerializer.Serialize(type);
}
else
{
try
{
return _typeNameSerializer.Serialize(type);
}
catch
{
if (FallbackSerializer == null)
{
throw;
}
else
{
return FallbackSerializer.Invoke(type);
}
}
}
}
public Type DeSerialize(string typeName)
{
if (FallbackFirst)
{
try
{
if (FallbackDeSerializer != null)
{
return FallbackDeSerializer.Invoke(typeName);
}
}
catch
{
// ignore
}
return _typeNameSerializer.DeSerialize(typeName);
}
else
{
try
{
return _typeNameSerializer.DeSerialize(typeName);
}
catch
{
if (FallbackDeSerializer == null)
{
throw;
}
return FallbackDeSerializer.Invoke(typeName);
}
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, my publisher and consumer are different projects, they're separated without any shared component,
it seemed when I publish a message it would write the message type info into the RabbitMQ message, and the consumer would try to deserialize the message according to the message type info, while the message type is not exists, so I get an error like follows:
Wondering that is there any way to support the different model types
The text was updated successfully, but these errors were encountered: