base.py 1003 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright © 2023 Ingram Micro Inc. All rights reserved.
  2. class BaseTransport:
  3. """
  4. CQRS pattern can be implemented over any transport (AMQP, HTTP, etc.)
  5. All transports need to inherit from this base class.
  6. Transport must be set in Django settings:
  7. ``` py3
  8. CQRS = {
  9. 'transport': 'dj_cqrs.transport.rabbit_mq.RabbitMQTransport',
  10. }
  11. ```
  12. """
  13. consumers = {}
  14. @staticmethod
  15. def produce(payload):
  16. """
  17. Send data from master model to replicas.
  18. Args:
  19. payload (dj_cqrs.dataclasses.TransportPayload): Transport payload from master model.
  20. """
  21. raise NotImplementedError
  22. @staticmethod
  23. def consume(*args, **kwargs):
  24. """Receive data from master model."""
  25. raise NotImplementedError
  26. @staticmethod
  27. def clean_connection(*args, **kwargs):
  28. """Clean transport connection. Here you can close all connections that you have"""
  29. raise NotImplementedError