Git Product home page Git Product logo

mqtttopicbuilder's Introduction


Build valid and verified MQTT topics

MqttTopicBuilder is a small library without any dependency that can help you to enforce the validity of your MQTT topics by using the provided builder.

Installation

You can find this projet on NuGet.

From the command line:

dotnet add package MqttTopicBuilder

From the package manager:

Install-Package MqttTopicBuilder

Usage

Using a custom builder, MqttTopicBuilder allows you to build topics and ensure their validity regarding the way you are planning to use them.

var subscribeTo = new TopicBuilder(TopicConsumer.Subscriber)
    .AddTopic("Hello")
    .AddTopic("From")
    .AddTopics("Mqtt", "Topic", "Builder")
    .AddMultiLevelWildcard()
    .Build();

Console.WriteLine(subscribeTo);
// -> "Hello/From/Mqtt/Topic/Builder/#"

var publishTop = new TopicBuilder(TopicConsumer.Publisher)
    .AddTopic("Hello")
    .AddTopic("From")
    .AddTopics("Mqtt", "Topic", "Builder")
    .AddMultiLevelWildcard()
    .Build();
// Will throw an exception since wildcards are not allowed when publishing
// on a topic

The object built is a Topic object. It can be used to both access the topic but also gather informations about it such as its level.

var topic = new TopicBuilder(TopicConsumer.Subscriber)
    .AddTopic("Hello")
    .AddTopic("World")
    .Build();

Console.WriteLine(topic.Value);
// -> "Hello/World"

Console.WriteLine(topic.Levels);
// -> 2

Topics can also be built using the regular constructor or the extension method:

var topic = Topic.FromString("Hello/World");
// or: var topic = (Topic) "Hello/World";

Console.WriteLine(topic.Value);
// -> "Hello/World"

Console.WriteLine(topic.Levels);
// -> 2

Topic integrity can also be checked using the TopicValidator methods

TopicValidator.ValidateTopic("a/wrong/#/Topic");
// Will throw an exception since no topic is allowed after '#'

"wrong+Topic".ValidateTopicForAppending();
// Will throw an exception since '+' is not allowed in a topic

Contributions

All contributions are welcome, please feel free to suggest pull requests ! You can read more about it in the CONTRIBUTING.md.

mqtttopicbuilder's People

Contributors

pbouillon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

starlord2826

mqtttopicbuilder's Issues

Create builder

Implements the builder with its operation to construct and generate topics

Improve README

Add CI badges and remove -Version 1.0.0 from the example

Upload project picture

Add a project picture to nuget

This project looks a bit sad for the moment, having a small picture to represent it would be way more user friendly !

Create website

Create a small one page site for this project to be linked to the nuget page


To make this project a little bit more user friendly and attract more people, a short landing page of
this product could be great.

It should be:

  • Short
  • One page
  • Located in a newly created docs/ folder
  • Be responsive

This can be based on the numerous templates available on GitHub like:

It does not have to be complex, you can keep is short and build it yourself if you want to !

Nuget license update

Actually, the following warning is reported while publishing the nuget package:

##[warning]/opt/hostedtoolcache/dncs/3.1.100/x64/sdk/3.1.100/Sdks/NuGet.Build.Tasks.Pack/build
/NuGet.Build.Tasks.Pack.targets(198,5): warning NU5125: The 'licenseUrl' element will be deprecated. 
Consider using the 'license' element instead. [/home/runner/work/MqttTopicBuilder/MqttTopicBuilder
/MqttTopicBuilder/MqttTopicBuilder.csproj]

We should upgrade the license format as specified here

Handle null char

Null char is forbidden in MQTT topics, adding a rule to prevent that would be great !

Parse and TryParse

Add methods Parse and TryParse to create a topic from a string

๐Ÿšจ Check and test illegal constructions (//, /#/+, etc.)

Populate the wiki

Every tool should be documented.

Of course, the documentation in the sources is great, but a external reference would be even better !

Ensure topic max size

Currently the maximum size of the topic is managed through Queue<T>(int capacity).

It would be great to ensure the maximum size of the queue and raise appropriate exception on overflow.

Topic Name

Looks like a clean library and that you had fun building it. A little bit of feedback:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.