def receive_request_and_send_response_message(service: MessagingService, for_requests: TopicSubscription):
        """Mimics microservice that performs a response

        Args:
            service: connected messaging service
            for_requests: where to expect requests
        """

        request_receiver: RequestReplyMessageReceiver = service.request_reply() \
            .create_request_reply_message_receiver_builder().build(for_requests).start()

        msg, replier = request_receiver.receive_message(timeout=5000)
        if replier is not None:
            outbound_msg = service.message_builder().build("pong reply")
            replier.reply(outbound_msg)
    def publish_request_and_process_response_message_async(service: MessagingService, request_destination: Topic,
                                                           reply_timeout: int):
        """Mimics microservice that performs a async request
        Args:
            service: connected messaging service
            request_destination: where to send a request (it is same for requests and responses)
            reply_timeout: the reply timeout
        """

        requester: RequestReplyMessagePublisher = service.request_reply() \
            .create_request_reply_message_publisher_builder().build().start()

        ping_message = service.message_builder().build(payload='Ping',
                                                       additional_message_properties={SEQUENCE_NUMBER: 123})

        publish_request_async = requester.publish(request_message=ping_message,
                                                  request_destination=request_destination,
                                                  reply_timeout=reply_timeout)
        # we can get the reply from the future
        print(publish_request_async.result())
    def publish_request_and_process_response_message_blocking(service: MessagingService, request_destination: Topic,
                                                              reply_timeout: int):
        """Mimics microservice that performs a blocking request

        Args:
            service: connected messaging service
            request_destination: where to send a request (it is same for requests and responses)
            reply_timeout: the reply timeout
        """
        requester: RequestReplyMessagePublisher = service.request_reply() \
            .create_request_reply_message_publisher_builder().build().start()

        ping_message: OutboundMessage = service.message_builder().build(payload='Ping')
        try:

            reply = requester.publish_await_response(request_message=ping_message,
                                                     request_destination=request_destination,
                                                     reply_timeout=reply_timeout)
            print(f"reply: {reply}")
        except TimeoutError as e:
            print(e)
    def request_reply_message_consume2(messaging_service: MessagingService, consumer_subscription: str,
                                       reply_timeout: int):
        """This method will create an receiver instance to receive str or byte array type message"""
        try:
            global MAX_SLEEP
            topic_subscription = TopicSubscription.of(consumer_subscription)
            group_name = ShareName.of('test')

            receiver = messaging_service.request_reply(). \
                create_request_reply_message_receiver_builder().build(request_topic_subscription=topic_subscription,
                                                                      share_name=group_name)
            receiver.start()
            msg, replier = receiver.receive_message(timeout=reply_timeout)
            print(f"incoming message is {msg.get_payload_as_string()}")
            if replier is not None:
                outbound_msg = messaging_service.message_builder().build("pong reply")
                replier.reply(outbound_msg)
            print(f"Subscribed to: {consumer_subscription}")
            time.sleep(MAX_SLEEP)
        finally:
            receiver.terminate()