diff --git a/melange/__init__.py b/melange/__init__.py index e69de29..39e4f0c 100644 --- a/melange/__init__.py +++ b/melange/__init__.py @@ -0,0 +1,24 @@ +from __future__ import absolute_import + +__title__ = "melange" +from melange.__version__ import __version__ # noqa + +__author__ = "David Jiménez" +__license__ = "Apache License 2.0" +__copyright__ = "Copyright 2022 David Jiménez, David Arthur, and Contributors" + +from melange.backends.factory import MessagingBackendFactory +from melange.consumers import Consumer, SingleDispatchConsumer, consumer +from melange.message_dispatcher import MessageDispatcher, SimpleMessageDispatcher +from melange.publishers import QueuePublisher, TopicPublisher + +__all__ = [ + "TopicPublisher", + "QueuePublisher", + "MessageDispatcher", + "SimpleMessageDispatcher", + "Consumer", + "SingleDispatchConsumer", + "consumer", + "MessagingBackendFactory", +] diff --git a/melange/backends/__init__.py b/melange/backends/__init__.py index e69de29..b039539 100644 --- a/melange/backends/__init__.py +++ b/melange/backends/__init__.py @@ -0,0 +1,18 @@ +from __future__ import absolute_import + +from melange.backends.backend_manager import BackendManager +from melange.backends.interfaces import MessagingBackend +from melange.backends.kafka import KafkaBackend +from melange.backends.sqs.localsqs import LocalSQSBackend +from melange.backends.sqs.sqs_backend import AWSBackend +from melange.backends.testing import InMemoryMessagingBackend, link_synchronously + +__all__ = [ + "link_synchronously", + "InMemoryMessagingBackend", + "MessagingBackend", + "BackendManager", + "KafkaBackend", + "LocalSQSBackend", + "AWSBackend", +] diff --git a/melange/examples/doc_examples/backend_manager.py b/melange/examples/doc_examples/backend_manager.py index 30d3fa3..0c5df2c 100644 --- a/melange/examples/doc_examples/backend_manager.py +++ b/melange/examples/doc_examples/backend_manager.py @@ -1,8 +1,7 @@ -from melange.backends.backend_manager import BackendManager -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import QueuePublisher +from melange.backends import BackendManager, LocalSQSBackend from melange.examples.shared import serializer_registry -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer class MyTestMessage: diff --git a/melange/examples/doc_examples/factory_complete.py b/melange/examples/doc_examples/factory_complete.py index 60a0a49..91b5f12 100644 --- a/melange/examples/doc_examples/factory_complete.py +++ b/melange/examples/doc_examples/factory_complete.py @@ -1,5 +1,5 @@ -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import MessagingBackendFactory +from melange.backends import LocalSQSBackend backend = LocalSQSBackend() factory = MessagingBackendFactory(backend) diff --git a/melange/examples/doc_examples/factory_queue.py b/melange/examples/doc_examples/factory_queue.py index 03ea1a9..9bd7812 100644 --- a/melange/examples/doc_examples/factory_queue.py +++ b/melange/examples/doc_examples/factory_queue.py @@ -1,5 +1,5 @@ -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import MessagingBackendFactory +from melange.backends import LocalSQSBackend backend = LocalSQSBackend() factory = MessagingBackendFactory(backend) diff --git a/melange/examples/doc_examples/factory_topic.py b/melange/examples/doc_examples/factory_topic.py index 6d7822d..076da71 100644 --- a/melange/examples/doc_examples/factory_topic.py +++ b/melange/examples/doc_examples/factory_topic.py @@ -1,5 +1,5 @@ -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.sqs_backend import AWSBackend +from melange import MessagingBackendFactory +from melange.backends import AWSBackend backend = AWSBackend() factory = MessagingBackendFactory(backend) diff --git a/melange/examples/doc_examples/serializer_example.py b/melange/examples/doc_examples/serializer_example.py index fc106e4..80668c9 100644 --- a/melange/examples/doc_examples/serializer_example.py +++ b/melange/examples/doc_examples/serializer_example.py @@ -5,7 +5,7 @@ from melange.exceptions import SerializationError from melange.helpers.typing import T -from melange.serializers.interfaces import Serializer +from melange.serializers import Serializer class MyOwnSerializer(Serializer): diff --git a/melange/examples/doc_examples/topic_publish.py b/melange/examples/doc_examples/topic_publish.py index a65c4f6..4c9a3e7 100644 --- a/melange/examples/doc_examples/topic_publish.py +++ b/melange/examples/doc_examples/topic_publish.py @@ -1,7 +1,7 @@ -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import TopicPublisher +from melange.backends import LocalSQSBackend from melange.examples.shared import serializer_registry -from melange.publishers import TopicPublisher -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer class MyTestMessage: diff --git a/melange/examples/doc_examples/tutorial/consume.py b/melange/examples/doc_examples/tutorial/consume.py index 7282a86..70e4190 100644 --- a/melange/examples/doc_examples/tutorial/consume.py +++ b/melange/examples/doc_examples/tutorial/consume.py @@ -1,11 +1,9 @@ from simple_cqrs.domain_event import DomainEvent -from melange.backends.sqs.localsqs import LocalSQSBackend -from melange.consumers import SingleDispatchConsumer, consumer +from melange import SimpleMessageDispatcher, SingleDispatchConsumer, consumer +from melange.backends import LocalSQSBackend from melange.examples.doc_examples.tutorial.publish import MyTestMessage -from melange.message_dispatcher import SimpleMessageDispatcher -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange.serializers import PickleSerializer, SerializerRegistry class MyConsumer(SingleDispatchConsumer): diff --git a/melange/examples/doc_examples/tutorial/create_queue.py b/melange/examples/doc_examples/tutorial/create_queue.py index b998478..81d93c1 100644 --- a/melange/examples/doc_examples/tutorial/create_queue.py +++ b/melange/examples/doc_examples/tutorial/create_queue.py @@ -1,5 +1,5 @@ -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import MessagingBackendFactory +from melange.backends import LocalSQSBackend backend = LocalSQSBackend(host="localhost", port=9324) factory = MessagingBackendFactory(backend) diff --git a/melange/examples/doc_examples/tutorial/publish.py b/melange/examples/doc_examples/tutorial/publish.py index 3eecc7c..620e45c 100644 --- a/melange/examples/doc_examples/tutorial/publish.py +++ b/melange/examples/doc_examples/tutorial/publish.py @@ -1,9 +1,8 @@ from simple_cqrs.domain_event import DomainEvent -from melange.backends.sqs.localsqs import LocalSQSBackend -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange import QueuePublisher +from melange.backends import LocalSQSBackend +from melange.serializers import PickleSerializer, SerializerRegistry class MyTestMessage: diff --git a/melange/examples/init_queues.py b/melange/examples/init_queues.py index 267fe90..a453e07 100644 --- a/melange/examples/init_queues.py +++ b/melange/examples/init_queues.py @@ -1,7 +1,7 @@ import os -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import MessagingBackendFactory +from melange.backends import LocalSQSBackend if __name__ == "__main__": backend = LocalSQSBackend( diff --git a/melange/examples/payment_service/app.py b/melange/examples/payment_service/app.py index fcb694b..ef436dc 100644 --- a/melange/examples/payment_service/app.py +++ b/melange/examples/payment_service/app.py @@ -1,14 +1,13 @@ import os -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import MessageDispatcher, QueuePublisher +from melange.backends import LocalSQSBackend from melange.examples.payment_service.consumer import PaymentConsumer from melange.examples.payment_service.publisher import PaymentPublisher from melange.examples.payment_service.repository import PaymentRepository from melange.examples.payment_service.service import PaymentService from melange.examples.shared import serializer_registry -from melange.message_dispatcher import MessageDispatcher -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer if __name__ == "__main__": serializer = PickleSerializer() diff --git a/melange/examples/payment_service/app_simpleconsumer.py b/melange/examples/payment_service/app_simpleconsumer.py index a331027..d94a1fd 100644 --- a/melange/examples/payment_service/app_simpleconsumer.py +++ b/melange/examples/payment_service/app_simpleconsumer.py @@ -1,14 +1,13 @@ import os -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import QueuePublisher, SimpleMessageDispatcher +from melange.backends import LocalSQSBackend from melange.examples.payment_service.consumer import PaymentConsumer from melange.examples.payment_service.publisher import PaymentPublisher from melange.examples.payment_service.repository import PaymentRepository from melange.examples.payment_service.service import PaymentService from melange.examples.shared import serializer_registry -from melange.message_dispatcher import SimpleMessageDispatcher -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer if __name__ == "__main__": serializer = PickleSerializer() diff --git a/melange/examples/payment_service/consumer.py b/melange/examples/payment_service/consumer.py index 41ffc7c..c459c27 100644 --- a/melange/examples/payment_service/consumer.py +++ b/melange/examples/payment_service/consumer.py @@ -1,4 +1,4 @@ -from melange.consumers import SingleDispatchConsumer, consumer +from melange import SingleDispatchConsumer, consumer from melange.examples.common.commands import DoPayment from melange.examples.payment_service.events import OrderResponse from melange.examples.payment_service.service import PaymentService diff --git a/melange/examples/payment_service/consumer_draft.py b/melange/examples/payment_service/consumer_draft.py index 696a970..ba8e42e 100644 --- a/melange/examples/payment_service/consumer_draft.py +++ b/melange/examples/payment_service/consumer_draft.py @@ -1,6 +1,6 @@ from typing import Any, Optional -from melange.consumers import Consumer +from melange import Consumer from melange.examples.common.commands import DoPayment from melange.examples.payment_service.events import OrderResponse from melange.examples.payment_service.service import PaymentService diff --git a/melange/examples/payment_service/publisher.py b/melange/examples/payment_service/publisher.py index db21b53..bb90523 100644 --- a/melange/examples/payment_service/publisher.py +++ b/melange/examples/payment_service/publisher.py @@ -1,5 +1,5 @@ +from melange import QueuePublisher from melange.examples.payment_service.events import OrderStatus -from melange.publishers import QueuePublisher class PaymentPublisher: diff --git a/melange/examples/payment_service/triggerer.py b/melange/examples/payment_service/triggerer.py index 0509588..587462d 100644 --- a/melange/examples/payment_service/triggerer.py +++ b/melange/examples/payment_service/triggerer.py @@ -2,11 +2,10 @@ import os import uuid -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import QueuePublisher +from melange.backends import LocalSQSBackend from melange.examples.payment_service.events import OrderResponse from melange.examples.shared import serializer_registry -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -16,7 +15,6 @@ args = parser.parse_args() order_reponse = OrderResponse(id=str(uuid.uuid4()), reference=args.reference) - serializer = PickleSerializer() backend = LocalSQSBackend( host=os.environ.get("SQSHOST"), port=os.environ.get("SQSPORT") ) diff --git a/melange/examples/saga_pattern/app.py b/melange/examples/saga_pattern/app.py index 3a22540..5be1e64 100644 --- a/melange/examples/saga_pattern/app.py +++ b/melange/examples/saga_pattern/app.py @@ -1,13 +1,12 @@ import os -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import QueuePublisher, SimpleMessageDispatcher +from melange.backends import LocalSQSBackend from melange.examples.saga_pattern.consumer import SagaConsumer from melange.examples.saga_pattern.publisher import SagaPublisher from melange.examples.saga_pattern.repository import SagaRepository from melange.examples.shared import serializer_registry -from melange.message_dispatcher import SimpleMessageDispatcher -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer if __name__ == "__main__": serializer = PickleSerializer() diff --git a/melange/examples/saga_pattern/consumer.py b/melange/examples/saga_pattern/consumer.py index 463d209..14ec6b5 100644 --- a/melange/examples/saga_pattern/consumer.py +++ b/melange/examples/saga_pattern/consumer.py @@ -1,7 +1,7 @@ import uuid from typing import Any -from melange.consumers import SingleDispatchConsumer, consumer +from melange import SingleDispatchConsumer, consumer from melange.examples.common.commands import DoPayment from melange.examples.payment_service.events import OrderResponse, OrderStatus from melange.examples.saga_pattern.models import Saga diff --git a/melange/examples/saga_pattern/publisher.py b/melange/examples/saga_pattern/publisher.py index 3a5cd99..016be9a 100644 --- a/melange/examples/saga_pattern/publisher.py +++ b/melange/examples/saga_pattern/publisher.py @@ -1,5 +1,5 @@ +from melange import QueuePublisher from melange.examples.common.commands import DoPayment -from melange.publishers import QueuePublisher class SagaPublisher: diff --git a/melange/examples/saga_pattern/saga_triggerer.py b/melange/examples/saga_pattern/saga_triggerer.py index 327d8bc..7b87958 100644 --- a/melange/examples/saga_pattern/saga_triggerer.py +++ b/melange/examples/saga_pattern/saga_triggerer.py @@ -2,11 +2,11 @@ import os import uuid -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import QueuePublisher +from melange.backends import LocalSQSBackend from melange.examples.payment_service.events import OrderResponse from melange.examples.shared import serializer_registry -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer if __name__ == "__main__": parser = argparse.ArgumentParser( diff --git a/melange/examples/shared.py b/melange/examples/shared.py index 0a7f6f6..ad2085a 100644 --- a/melange/examples/shared.py +++ b/melange/examples/shared.py @@ -1,7 +1,6 @@ from simple_cqrs.domain_event import DomainEvent -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange.serializers import PickleSerializer, SerializerRegistry serializer_settings = { "serializers": {"pickle": PickleSerializer}, diff --git a/melange/serializers/__init__.py b/melange/serializers/__init__.py index e69de29..b559e7d 100644 --- a/melange/serializers/__init__.py +++ b/melange/serializers/__init__.py @@ -0,0 +1,13 @@ +from __future__ import absolute_import + +__all__ = [ + "Serializer", + "JsonSerializer", + "PickleSerializer", + "SerializerRegistry", +] + +from melange.serializers.interfaces import Serializer +from melange.serializers.json import JsonSerializer +from melange.serializers.pickle import PickleSerializer +from melange.serializers.registry import SerializerRegistry diff --git a/tests/backends/test_factory.py b/tests/backends/test_factory.py index ad6d331..b46bc27 100644 --- a/tests/backends/test_factory.py +++ b/tests/backends/test_factory.py @@ -3,8 +3,8 @@ import pytest from hamcrest import * -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange import MessagingBackendFactory +from melange.backends import LocalSQSBackend class TestFactory: diff --git a/tests/backends/test_localsqs.py b/tests/backends/test_localsqs.py index 06329aa..bcdd306 100644 --- a/tests/backends/test_localsqs.py +++ b/tests/backends/test_localsqs.py @@ -6,7 +6,7 @@ import pytest from hamcrest import * -from melange.backends.sqs.localsqs import LocalSQSBackend +from melange.backends import LocalSQSBackend from melange.models import Message diff --git a/tests/doc_examples/test_async.py b/tests/doc_examples/test_async.py index ded842e..025449b 100644 --- a/tests/doc_examples/test_async.py +++ b/tests/doc_examples/test_async.py @@ -6,13 +6,14 @@ import polling from hamcrest import * -from melange.backends.factory import MessagingBackendFactory -from melange.backends.sqs.localsqs import LocalSQSBackend -from melange.consumers import Consumer -from melange.message_dispatcher import SimpleMessageDispatcher -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange import ( + Consumer, + MessagingBackendFactory, + QueuePublisher, + SimpleMessageDispatcher, +) +from melange.backends import LocalSQSBackend +from melange.serializers import PickleSerializer, SerializerRegistry from tests.probe import Probe diff --git a/tests/doc_examples/test_testing.py b/tests/doc_examples/test_testing.py index 96e4dd1..ee0aecb 100644 --- a/tests/doc_examples/test_testing.py +++ b/tests/doc_examples/test_testing.py @@ -1,8 +1,6 @@ -from melange.backends.testing import InMemoryMessagingBackend, link_synchronously -from melange.consumers import Consumer -from melange.publishers import QueuePublisher -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange import Consumer, QueuePublisher +from melange.backends import InMemoryMessagingBackend, link_synchronously +from melange.serializers import PickleSerializer, SerializerRegistry serializer_settings = { "serializers": { diff --git a/tests/fixtures.py b/tests/fixtures.py index 2e4fbf8..c02e33a 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,8 +1,8 @@ import json from typing import Any, Optional -from melange.consumers import SingleDispatchConsumer, consumer -from melange.serializers.interfaces import Serializer +from melange import SingleDispatchConsumer, consumer +from melange.serializers import Serializer class BaseMessage: diff --git a/tests/serializers/test_registry.py b/tests/serializers/test_registry.py index b7f60fe..9345b37 100644 --- a/tests/serializers/test_registry.py +++ b/tests/serializers/test_registry.py @@ -2,9 +2,8 @@ from hamcrest import * -from melange.serializers.json import JsonSerializer -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry, sort +from melange.serializers import JsonSerializer, PickleSerializer, SerializerRegistry +from melange.serializers.registry import sort from tests.fixtures import ( BananaHappened, BaseMessage, diff --git a/tests/test_message_dispatcher.py b/tests/test_message_dispatcher.py index a066ec8..c9811ea 100644 --- a/tests/test_message_dispatcher.py +++ b/tests/test_message_dispatcher.py @@ -3,12 +3,10 @@ from doublex import ANY_ARG, ProxySpy, Spy, called, never from hamcrest import * -from melange.backends.interfaces import MessagingBackend -from melange.message_dispatcher import SimpleMessageDispatcher +from melange import SimpleMessageDispatcher +from melange.backends import MessagingBackend from melange.models import Message -from melange.serializers.json import JsonSerializer -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange.serializers import JsonSerializer, PickleSerializer, SerializerRegistry from tests.fixtures import ( BananaConsumer, BananaHappened, diff --git a/tests/test_pickleserializer.py b/tests/test_pickleserializer.py index db2b4e6..c15778d 100644 --- a/tests/test_pickleserializer.py +++ b/tests/test_pickleserializer.py @@ -3,7 +3,7 @@ from hamcrest import * from melange.examples.payment_service.events import OrderResponse -from melange.serializers.pickle import PickleSerializer +from melange.serializers import PickleSerializer def test_pickle_a_domain_event(): diff --git a/tests/test_publishers.py b/tests/test_publishers.py index 31820f3..b83fb07 100644 --- a/tests/test_publishers.py +++ b/tests/test_publishers.py @@ -3,11 +3,9 @@ from doublex import ANY_ARG, Spy, called from hamcrest import * -from melange.backends.interfaces import MessagingBackend -from melange.publishers import QueuePublisher -from melange.serializers.json import JsonSerializer -from melange.serializers.pickle import PickleSerializer -from melange.serializers.registry import SerializerRegistry +from melange import QueuePublisher +from melange.backends import MessagingBackend +from melange.serializers import JsonSerializer, PickleSerializer, SerializerRegistry from tests.fixtures import BaseMessage, MessageStubInterface, SerializerStub