How to use the rele.publishing.init_global_publisher function in rele

To help you get started, we’ve selected a few rele examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mercadona / rele / tests / test_publishing.py View on Github external
def test_creates_global_publisher_when_published_called(
        self, mock_publisher, config
    ):
        mock_publisher.return_value = MagicMock(spec=Publisher)
        publishing.init_global_publisher(config)
        message = {"foo": "bar"}
        publishing.publish(topic="order-cancelled", data=message, myattr="hello")
        assert isinstance(publishing._publisher, Publisher)
        publisher_id = id(publishing._publisher)

        mock_publisher.return_value.publish.assert_called_with(
            "order-cancelled", {"foo": "bar"}, myattr="hello"
        )

        mock_publisher.return_value = MagicMock(spec=Publisher)
        publishing.publish(topic="order-cancelled", data=message, myattr="hello")
        assert id(publishing._publisher) == publisher_id
github mercadona / rele / rele / config.py View on Github external
def setup(setting=None, **kwargs):
    if setting is None:
        setting = {}

    config = Config(setting)
    init_global_publisher(config)
    register_middleware(config, **kwargs)
    return config