Пример #1
0
    def subscribe(
        self,
        destination: str,
        ack: str = 'auto',
        extra_headers=None,
        handler=None,
        auto_ack=True,
    ) -> Subscription:
        extra_headers = extra_headers or {}
        self._last_subscribe_id += 1

        subscription = Subscription(
            destination=destination,
            id=self._last_subscribe_id,
            ack=ack,
            extra_headers=extra_headers,
            handler=handler,
            auto_ack=auto_ack,
        )

        self._subscriptions[str(self._last_subscribe_id)] = subscription

        if self._connected:
            self._protocol.subscribe(subscription)

        return subscription
Пример #2
0
    async def test_can_unsubscribe(self):
        handler = Mock()
        subscription = Subscription("/queue/123", 1, "client",
                                    {"my-header": "my-value"}, handler)

        await self.protocol.connect()
        self.protocol.unsubscribe(subscription)

        self._protocol.send_frame.assert_called_with(
            "UNSUBSCRIBE", {
                "id": 1,
                "destination": "/queue/123"
            })
Пример #3
0
    async def test_can_unsubscribe(self):
        handler = Mock()
        subscription = Subscription('/queue/123', 1, 'client',
                                    {'my-header': 'my-value'}, handler)

        await self.protocol.connect()
        self.protocol.unsubscribe(subscription)

        self._protocol.send_frame.assert_called_with(
            'UNSUBSCRIBE', {
                'id': 1,
                'destination': '/queue/123',
            })
Пример #4
0
    def subscribe(self, destination, ack='auto', extra_headers={}, handler=None):
        self._last_subscribe_id += 1

        subscription = Subscription(
            destination=destination,
            id=self._last_subscribe_id,
            ack=ack,
            extra_headers=extra_headers,
            handler=handler)

        self._subscriptions[str(self._last_subscribe_id)] = subscription

        if self._connected:
            self._protocol.subscribe(subscription)

        return subscription
Пример #5
0
    async def test_can_handle_message(self):
        frame = Frame("MESSAGE", {
            "subscription": "123",
            "message-id": "321"
        }, "blah")

        handler = CoroutineMock()
        subscription = Subscription("123", 1, "auto", {}, handler)

        frame_handler = Mock()
        frame_handler.get.return_value = subscription

        stomp = StompReader(frame_handler, self.loop)
        await stomp._handle_message(frame)

        handler.assert_called_with(frame, frame.body)
Пример #6
0
    async def test_can_handle_message(self):
        frame = Frame('MESSAGE', {
            'subscription': '123',
            'message-id': '321'
        }, 'blah')

        handler = CoroutineMock()
        subscription = Subscription('123', 1, 'auto', {}, handler)

        frame_handler = Mock()
        frame_handler.get.return_value = subscription

        stomp = StompReader(frame_handler, self.loop)
        await stomp._handle_message(frame)

        handler.assert_called_with(frame, frame.body)
Пример #7
0
    async def test_can_handle_message_can_nack(self, send_frame_mock):
        frame = Frame("MESSAGE", {
            "subscription": "123",
            "message-id": "321"
        }, "blah")

        handler = CoroutineMock()
        handler.return_value = False
        subscription = Subscription("123", 1, "client-individual", {}, handler)

        frame_handler = Mock()
        frame_handler.get.return_value = subscription

        stomp = StompReader(frame_handler, self.loop)
        await stomp._handle_message(frame)

        handler.assert_called_with(frame, frame.body)
        send_frame_mock.assert_called_with("NACK", {
            "subscription": "123",
            "message-id": "321"
        })
Пример #8
0
    async def test_can_handle_message_can_nack(self, send_frame_mock):
        frame = Frame('MESSAGE', {
            'subscription': '123',
            'message-id': '321'
        }, 'blah')

        handler = CoroutineMock()
        handler.return_value = False
        subscription = Subscription('123', 1, 'client-individual', {}, handler)

        frame_handler = Mock()
        frame_handler.get.return_value = subscription

        stomp = StompReader(frame_handler, self.loop)
        await stomp._handle_message(frame)

        handler.assert_called_with(frame, frame.body)
        send_frame_mock.assert_called_with('NACK', {
            'subscription': '123',
            'message-id': '321'
        })
Пример #9
0
    def subscribe(self,
                  destination,
                  ack='auto',
                  extra_headers=None,
                  handler=None,
                  auto_ack=True):
        extra_headers = {} if extra_headers is None else extra_headers
        self._last_subscribe_id += 1

        subscription = Subscription(destination=destination,
                                    id=self._last_subscribe_id,
                                    ack=ack,
                                    extra_headers=extra_headers,
                                    handler=handler,
                                    auto_ack=auto_ack)

        self._subscriptions[str(self._last_subscribe_id)] = subscription

        if self._connected:
            self._protocol.subscribe(subscription)

        return subscription