celper
celper

Reputation: 175

ServiceStack.RabbitMq.RabbitMqProducer: Override PublishMessage()

I want to override ServiceStack.RabbitMq.RabbitMqProducer.PublishMessage() in order to omit the queue declaration in case of server named queues:

    public void PublishMessage(string exchange, string routingKey, IBasicProperties basicProperties, byte[] body)
    {
        try
        {
            if (routingKey.IsServerNamedQueue()) // In case of server named queues (client declared queue with channel.declare()), assume queue already exists (redeclaration would result in error anyway since queue was marked as exclusive) and publish to default exchange
            {
                Channel.BasicPublish("", routingKey, basicProperties, body);
            }
            else
            {
                if (!Queues.Contains(routingKey))
                {
                    Channel.RegisterQueueByName(routingKey);
                    Queues = new HashSet<string>(Queues) { routingKey };
                }

                Channel.BasicPublish(exchange, routingKey, basicProperties, body);
            }
...

with extension method

    public static bool IsServerNamedQueue(this string queueName)
    {
        if (string.IsNullOrEmpty(queueName))
        {
            throw new ArgumentNullException("queueName");
        }

        return queueName.ToLower().StartsWith("amq.");
    }

Unfortunately, PublishMessage is not virtual AND there are some depedencies between the mq classes (e.g. RabbitMqQueueClient inherits from RabbitMqProducer), which would require me to reimplement the whole IMessageService myself.

Is there an easier way to accomplish this?

Upvotes: 1

Views: 83

Answers (1)

celper
celper

Reputation: 175

mythz merged proposed changes into service stack master branch. Available in version v4.0.32+.

Upvotes: 2

Related Questions