Skip to content
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

[request of improvement] Expose a callback as "OnTrasportMessageCreate" for custom logic #126

Open
NiSHoW opened this issue Dec 6, 2024 · 0 comments

Comments

@NiSHoW
Copy link

NiSHoW commented Dec 6, 2024

I am trying to use rebus in an integration project between different partners, using the configuration that I report below.
(It is a configuration in order to use topics to manage the publication)

services.AddRebus(conf =>
    conf.Serialization((s) =>
    {
        s.UseNewtonsoftJson(new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.None,
        });
        s.UseCustomMessageTypeNames().AddWithCustomName<Message<OMIssue>>("omissue");
    })
    .Options(o =>
    {
        o.Decorate<ITopicNameConvention>(c =>
        {
            var messageTypeNameConvention = c.Get<IMessageTypeNameConvention>();
            return new TopicNameConvention(messageTypeNameConvention);
        });
    })
    .Transport(t =>
    {
        var options = t.UseRabbitMq($"amqps://localhost/host", "input-queue")
            .ExchangeNames("directs", "topics")
            .Declarations(declareExchanges: false)
            .Ssl(new Rebus.RabbitMq.SslSettings(false, ""))
            .CustomizeConnectionFactory(factory =>
            {
                var scoppes = string.Join(" ", [
                        "orange-bus.read:orange/topics/omissue",
                        "orange-bus.read:orange/directs/*",
                        "orange-bus.write:orange/directs/*",
                        $"orange-bus.read:orange/input-queue/*",
                        $"orange-bus.write:orange/input-queue/*",
                        $"orange-bus.configure:orange/input-queue/*",
                        $"orange-bus.write:orange/error/*",
                        $"orange-bus.configure:orange/error/*"
                    ]);

                var authclient = new OAuth2ClientBuilder("username", "password", new Uri("https://identityserver/connect/token"))
                    .SetScope(scoppes)
                    .Build();

                factory.ClientProvidedName = "SubscriberExample";
                factory.CredentialsProvider = new OAuth2ClientCredentialsProvider("orange", authclient);
                return factory;
            });
    }),
    onCreated: async bus =>
    {
        await bus.Subscribe<Message<OMIssue>>();
    },
    isDefaultBus: true
);

Rebus rightly provides for the use of these two custom headers for the deserialization of messages in order to know the type. Unfortunately, however, I cannot ask partners (who use other tools, to insert these specific headers)

    ["rbs2-content-type"] = "application/json",
    ["rbs2-msg-type"] = "my-topics-routing-key"

I therefore wanted to ask you if it is possible to add a Callback to be able to access the exchange information (BasicDeliverEventArgs) in order to be able to alter the TransportMessage and add the headers that are needed

return CreateTransportMessage(result.BasicProperties, result.Body.ToArray());

Alternatively, I ask you if it is possible to make the method

internal static TransportMessage CreateTransportMessage(IBasicProperties basicProperties, byte[] body)

overridable (making it protected not static) and with access to the BasicDeliverEventArgs so that by creating a decorator of the Transport you can implement custom logic

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant