MqTest.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * main.c
  3. *
  4. * Created on: 2019��3��13��
  5. * Author: root
  6. */
  7. #include "../Sers/Mq/SocketMq/ClientMq.h"
  8. #include <string>
  9. #include "../Sers/Core/Module/Api/ApiClient.hpp"
  10. #include "../Sers/Core/Module/Log/Logger.hpp"
  11. #include "../Sers/Core/Util/Common/CommonHelp.hpp"
  12. #include "../Sers/Core/Util/ConfigurationManager/JsonFile.hpp"
  13. //////////////////////////////////////////////////////////////////
  14. // Logger test
  15. using namespace Sers::Core::Util::ConfigurationManager;
  16. using namespace Sers::Core::Module::Log;
  17. void LoggerTest(){
  18. //(x.1) Logger
  19. Logger::Info("start");
  20. Logger::Error("throws exception");
  21. Sers::Core::Module::Log::Logger::Error("fail");
  22. //(x.2)ConfigurationManager
  23. string t3=JsonFile::ConfigurationManager.GetStringByPath("Sers.test");
  24. //(x.3)JsonFile
  25. Sers::Core::Util::ConfigurationManager::JsonFile json("appsettings.json");
  26. string t2=json.GetStringByPath("Sers.test");
  27. }
  28. // Logger test
  29. //////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////
  31. // Mq test
  32. using namespace std;
  33. using namespace Sers::Core::Data;
  34. void OnReceiveRequest(Sers::Mq::SocketMq::MqConnect & mq,const ArraySegment & requestData,ByteData & replyData )
  35. {
  36. replyData.InsertData(requestData);
  37. }
  38. Sers::Core::Util::Threading::AutoResetEvent mEvent;
  39. void OnDisConnected()
  40. {
  41. printf("mq stoped");
  42. mEvent.Set();
  43. }
  44. void MqTest(){
  45. Sers::Mq::SocketMq::ClientMq mq;
  46. //mq.config.host="192.168.10.100";
  47. mq.config.host="127.0.0.1";
  48. mq.config.port=4501;
  49. mq.config.secretKey="SersSocketMq";
  50. mq.OnDisConnected_Set(&OnDisConnected);
  51. mq.OnReceiveRequest_Set(OnReceiveRequest);
  52. if(!mq.Connect())
  53. {
  54. printf("���ӷ����� fail. exit");
  55. return ;
  56. }
  57. printf("mq connect succeed! ");
  58. mEvent.WaitOne();
  59. printf("main stoped");
  60. }
  61. // Mq test
  62. //////////////////////////////////////////////////////////////////