rebus-org / Rebus.AzureServiceBus

:bus: Azure Service Bus transport for Rebus
https://mookid.dk/category/rebus
Other
33 stars 20 forks source link

/ in topic name #25

Closed Meyce closed 5 years ago

Meyce commented 5 years ago

Queue names are allowed to have / but topics do not. Topics can be organized using slashes similar to queues. In most clients that visualize queues and topics the parts of the path end up acting like virtual directories.

https://github.com/rebus-org/Rebus.AzureServiceBus/blob/99e79a5746527ff09e23cbed45b10a246b6e5a84/Rebus.AzureServiceBus/AzureServiceBus/AzureServiceBusNameHelper.cs#L41 I tested this with an update to AzureServiceBusNameHelper.cs to allow / and a decorator on the ISubscriptionStorage like below and it worked as expected. Would it be possible to update this so the / is allowed for topic names. The decorator is below with a screenshot from Service Bus Explorer. The decorator alters the topic names so that the name comes out {assembly name}/{fully qualified type name} which through most software that visualizes topics and queues makes all the types from the same assembly appear nested in the same virtual directory.

    public class NamespaceNestedSubscriptionStorage : ISubscriptionStorage
    {
        private readonly ISubscriptionStorage _toDecorate;

        public NamespaceNestedSubscriptionStorage(ISubscriptionStorage toDecorate)
        {
            _toDecorate = toDecorate;
        }
        public Task<string[]> GetSubscriberAddresses(string topic)
        {
            return _toDecorate.GetSubscriberAddresses(AssemblyNested(topic));
        }

        public Task RegisterSubscriber(string topic, string subscriberAddress)
        {
            return _toDecorate.RegisterSubscriber(AssemblyNested(topic), subscriberAddress);
        }

        public Task UnregisterSubscriber(string topic, string subscriberAddress)
        {
            return _toDecorate.UnregisterSubscriber(AssemblyNested(topic), subscriberAddress);
        }

        private string AssemblyNested(string originalTopic)
        {
            var split = originalTopic.Split("__");
            return $"{split[1]}/{split[0]}";
        }

        public bool IsCentralized => _toDecorate.IsCentralized;
    }

image

mookid8000 commented 5 years ago

Should be fixed and released as Rebus.AzureServiceBus 7.0.0-a06