pyjson.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright 2021 EMQ Technologies Co., Ltd.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. # Licensed under the Apache License, Version 2.0 (the "License");
  16. # you may not use this file except in compliance with the License.
  17. # You may obtain a copy of the License at
  18. #
  19. # http://www.apache.org/licenses/LICENSE-2.0
  20. #
  21. # Unless required by applicable law or agreed to in writing, software
  22. # distributed under the License is distributed on an "AS IS" BASIS,
  23. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. # See the License for the specific language governing permissions and
  25. # limitations under the License.
  26. import logging
  27. import time
  28. from ekuiper import Source, Context
  29. class PyJson(Source):
  30. def __init__(self):
  31. self.data = {"name": "pyjson", "value": 2021}
  32. def configure(self, datasource: str, conf: dict):
  33. logging.info("configuring with datasource {} and conf {}".format(datasource, conf))
  34. # noinspection PyTypeChecker
  35. def open(self, ctx: Context):
  36. print("opening")
  37. for i in range(100):
  38. ctx.emit(self.data, None)
  39. print("emit")
  40. time.sleep(0.2)
  41. def close(self, ctx: Context):
  42. print("closing")