Topic Naming Validation via Regex

Options
ahabel
ahabel Member Posts: 9 ✭✭

Hi Solace Community,

I wonder if anyone else before had the need to validate topic names (including wildcards), for example in CI/CD pipelines.

Because I couldn't find anything, I've tried myself to assemble a regex that validates the general structure of topic names. By no means I feel like it's perfect, however at least it matches my few examples.

In this case I assume that topic parts should only contain small characters plus numbers and "_" or "-"

^(?:(?:[a-z0-9_-]+|[a-z0-9_-]+\*|\*)\/)*([a-z0-9_-]+|[a-z0-9_-]+\*|\*|>)$

# MATCH
my/simple/topic/123
my/simple/topic/123/>
my/simple/topic/123/*
my/simple/to*/123/*
my/simple/topic/*/*/>
*/simple/topic/>
my
*
>

# NO MATCH
my/*imple/topic
my/simple/topic/
my/simple/topic/>/123

I'd really like to get your feedback if you have something better in place :-)

Maybe there's even something officially available?

regards,

Andreas

Tagged:

Comments

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 493 admin
    Options

    ouuh interesting! I personally have not seen a tool that is dedicated to topic validation, however I think this could be a good project for the github.com/SolaceCommunity. Thinking out loud, this could be a library or a utility to validate topic prior to publishing (similar to schema validation). Curious to know what other use-cases this could have (apart from the CI/CD usecase you mentioned).

    I'm interested to hear from others in the community as well if they have developed a Soalce topic validator, any use-cases, or if anyone would find this helpful?

  • ChristianHoltfurth
    ChristianHoltfurth Member, Employee Posts: 68 Solace Employee
    edited February 2022 #3
    Options

    Hi @ahabel,

    I love the idea of this (as I love RegEx) and I feel like this should be achievable and possibly someone has something already out there. I wanted to have a stab at this myself, just haven't found the time (yet).

    Just some thoughts on your RegEx:

    • While sticking to lower case ascii is probably a good idea, it's not really required by Solace. Solace supports the full UTF-8 character set and users in APAC will probably find it useful to be able to use Chinese, Japanese, Korean or similar as part of their topic names.
    • I would mainly exclude the use of wildcard characters like "*" and ">" for SMF or "+" and "#" for MQTT in the topic as they can cause issues when trying to match your subscriptions to those topics.
    • Another one to check for is the overall topic length not being larger than 255 characters.

    Christian