diff --git a/doc/config b/doc/config index 32cb5b8..d76aa82 100644 --- a/doc/config +++ b/doc/config @@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "Message Queue" +PROJECT_NAME = "KawaiiMQ" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -54,7 +54,7 @@ PROJECT_NUMBER = # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = "A simple message queue implementation" +PROJECT_BRIEF = "A simple generic message queue implementation" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 @@ -1047,7 +1047,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = ./dependencies ./scripts ./build ./cmake-build-debug +EXCLUDE = ./dependencies ./scripts ./src/test # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -1063,7 +1063,7 @@ EXCLUDE_SYMLINKS = NO # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = */cmake-build-*/* */build/* # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -1768,7 +1768,7 @@ FORMULA_MACROFILE = # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -USE_MATHJAX = NO +USE_MATHJAX = YES # With MATHJAX_VERSION it is possible to specify the MathJax version to be used. # Note that the different versions of MathJax have different requirements with @@ -1976,7 +1976,7 @@ LATEX_MAKEINDEX_CMD = makeindex # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. -COMPACT_LATEX = NO +COMPACT_LATEX = YES # The PAPER_TYPE tag can be used to set the paper type that is used by the # printer. diff --git a/doc/examples.md b/doc/examples.md index 7e9dc2b..a00202c 100644 --- a/doc/examples.md +++ b/doc/examples.md @@ -2,26 +2,91 @@ > All examples assume you included the header file `KawaiiMQ/kawaiiMQ.h` -## 1. Creating a message queue -```c++ +## Usage example + +To use a message queue, you need to create a queue and a topic. + +```cpp KawaiiMQ::Queue queue; +KawaiiMQ::Topic topic("topic1"); ``` -## 2. Relating a message queue with a topic +Then, you need to relate the queue with the topic. -```c++ +```cpp +KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); +``` -KawaiiMQ::MessageQueue queue; +After that, you can create a producer and subscribe to the topic. + +```cpp +KawaiiMQ::Producer producer; +producer.subscribe(topic); +``` + +To make a message, use the `makeMessage` function. + +```cpp +auto message = KawaiiMQ::makeMessage(0); +``` + +Then, you can publish the message. + +```cpp +producer.publishMessage(topic, message); +``` + +To consume the message, you need to create a consumer and fetch the message. + +```cpp +auto consumer = KawaiiMQ::Consumer({topic}); +auto messages = consumer.fetchMessage(); +``` + +The return value is a map of topics and messages. You can use the `getMessage` function to get the message. + +```cpp +std::cout << getMessage(messages[topic][0]) << std::endl; +``` + +You can of course only publish message on a single topic or consume messages from a single topic. + +```cpp +KawaiiMQ::Queue queue; KawaiiMQ::Topic topic("topic1"); KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); +KawaiiMQ::Producer producer; +producer.subscribe(topic); +auto message = KawaiiMQ::makeMessage(0); +producer.publishMessage(topic, message); +auto consumer = KawaiiMQ::Consumer({topic}); +consumer.subscribe(topic); +auto messages = consumer.fetchSingleTopic(topic); +std::cout << getMessage(messages[0]) << std::endl; +``` +## More examples + +### Creating a message queue + +```cpp +KawaiiMQ::Queue queue; ``` -## 3. Publishing a message +### Relating a message queue with a topic + +```cpp + +KawaiiMQ::MessageQueue queue; +KawaiiMQ::Topic topic("topic1"); +KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); + +``` -```c++ +### Publishing a message +```cpp KawaiiMQ::Queue queue; KawaiiMQ::Topic topic("topic1"); KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); @@ -29,12 +94,11 @@ KawaiiMQ::Producer producer; producer.subscribe(topic); auto message = KawaiiMQ::makeMessage(0); producer.publishMessage(topic, message); - ``` -## 4. Consuming a message +### Consuming a message -```c++ +```cpp KawaiiMQ::Queue queue; KawaiiMQ::Topic topic("topic1"); KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); @@ -49,9 +113,9 @@ std::cout << getMessage(messages[topic][0]) << std::endl; The output will be `0`. -## 5. Unrelate a message queue with a topic +### Unrelate a message queue with a topic -```c++ +```cpp KawaiiMQ::Queue queue; KawaiiMQ::Topic topic("topic1"); KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); @@ -59,10 +123,10 @@ KawaiiMQ::MessageQueueManager::Instance()->unrelate(topic, queue); ``` > Note this method will wait till the queue is empty before unrelating the queue with the topic. -> -## 6. Unsubscribe a topic, both consumer and producer -```c++ +### Unsubscribe a topic, both consumer and producer + +```cpp KawaiiMQ::Queue queue; KawaiiMQ::Topic topic("topic1"); KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue); diff --git a/include/KawaiiMQ/Exceptions.h b/include/KawaiiMQ/Exceptions.h index 7c041d0..7960f91 100644 --- a/include/KawaiiMQ/Exceptions.h +++ b/include/KawaiiMQ/Exceptions.h @@ -2,7 +2,7 @@ * @file Exceptions.h * @author ayano * @date 1/29/24 - * @brief + * @brief Exceptions for KawaiiMQ */ #ifndef KAWAIIMQ_EXCEPTIONS_H diff --git a/include/KawaiiMQ/Message.h b/include/KawaiiMQ/Message.h index 9edab01..407dfab 100644 --- a/include/KawaiiMQ/Message.h +++ b/include/KawaiiMQ/Message.h @@ -26,7 +26,6 @@ namespace KawaiiMQ { * @tparam T type of message content */ template - requires std::is_convertible_v || std::is_fundamental_v class Message : public MessageData { public: explicit Message(T content) : content(std::move(content)) {} @@ -54,7 +53,6 @@ namespace KawaiiMQ { * @exception TypeException Will throw if the type of the message is not the same as the type you are expecting */ template - requires std::is_convertible_v || std::is_fundamental_v T getMessage(std::shared_ptr in) { std::shared_ptr> tmp = std::dynamic_pointer_cast>(in); if (tmp != nullptr) { @@ -71,7 +69,6 @@ namespace KawaiiMQ { * @return message shared ptr */ template - requires std::is_convertible_v || std::is_fundamental_v std::shared_ptr> makeMessage(T content) { auto msg = std::make_shared>(content); return msg;