1

I need to implement pub/sub using Rebus between two microservices which are in two different assemblies. In this case, the publisher use an object which is in . The subscriber is in but declares the same type. (namespace, class is the same). Doing this I've encountered the following exception

System.FormatException: Could not get .NET type named 'TYPEA, ASSEMBLYA'

on sub side. Obviously it tries to get a type which is in another assembly, and of course it fails. Is there a way to use only the type + namespace and not the assembly type, so the pub/sub can be implemented, without creating an assembly and link it to both the sub and the publisher? Reading "Rebus" poor documentation there is a IMessageTypeNameConvention that can be implemented, but cannot find any example.

1 Answer 1

0

You're on the right track with IMessageTypeNameConvention – you can either use it by implementing it yourself and registering it, or you can use Rebus' built-in ability to prefer short type names for some specific types:


services.AddRebus(configure => configure
    .(...)
    .Serialization(s => s.UseCustomMessageTypeNames()
        .AddWithShortNames([typeof(YourMessage), typeof(YourOtherMessage)]))
);

where you'll then have to list all the possible message types, which then just need to match with their type and property names.

The reason you need to specify the message types, is that Rebus needs to be able to look up the type from a short string like e.g. "MyFavoriteMessage", which on the sender's side was actually "MySender.MyFavoriteMessage, MySender" and in the receiver's end must be mapped to "MyReceiver.MyFavoriteMessage, MyReceiver".

I hope that makes sense 🙂

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.