kafka_handler.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*************************************************************************
  2. * Copyright (C) [2020] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #ifndef MODULES_KAFKA_INCLUDE_HANDLER_HPP_
  21. #define MODULES_KAFKA_INCLUDE_HANDLER_HPP_
  22. #include <memory>
  23. #include <string>
  24. #include "cnstream_frame_va.hpp"
  25. #include "reflex_object.h"
  26. namespace cnstream {
  27. using CNFrameInfoPtr = std::shared_ptr<CNFrameInfo>;
  28. class KafkaClient;
  29. class KafkaHandler : virtual public ReflexObjectEx<KafkaHandler> {
  30. public:
  31. static KafkaHandler *Create(const std::string &name);
  32. virtual ~KafkaHandler() {}
  33. virtual int UpdateFrame(const CNFrameInfoPtr &data) { return 0; }
  34. friend class Kafka;
  35. protected:
  36. bool Produce(const std::string &content);
  37. bool Consume(std::string *content, int timeout_ms);
  38. private:
  39. std::string brokers_;
  40. std::string topic_;
  41. std::unique_ptr<KafkaClient> producer_ = nullptr;
  42. std::unique_ptr<KafkaClient> consumer_ = nullptr;
  43. }; // class KafkaHandler
  44. } // namespace cnstream
  45. #endif // ifndef MODULES_KAFKA_INCLUDE_HANDLER_HPP_