def test_delayed_transaction_message_pass(self):
        queue_name = "transaction_message_pass"
        client_id = "transaction_message_pass"
        kube_add = "localhost:50000"
        queue = MessageQueue(queue_name, client_id, kube_add)
        mm = []

        queuePolicy = QueueMessagePolicy(DelaySeconds=3)
        message = create_queue_message("queueName {}".format(0),
                                       "first test Ack".encode('UTF-8'),
                                       queuePolicy)
        mm.append(message)

        queuePolicy2 = QueueMessagePolicy(DelaySeconds=5)
        message2 = create_queue_message("queueName {}".format(1),
                                        "first test Ack".encode('UTF-8'),
                                        queuePolicy2)
        mm.append(message2)
        queue.send_queue_messages_batch(mm)

        tr = queue.create_transaction()
        recm = tr.receive()
        self.assertEqual(
            recm.error,
            "Error 138: no new message in queue, wait time expired")
        tr.close_stream()
        time.sleep(0.1)

        recm = tr.receive(2, 3)
        self.assertFalse(recm.is_error)
        tr.close_stream()
        time.sleep(0.01)

        recm = tr.receive(2, 5)
        self.assertFalse(recm.is_error)
    def test_delayed_message_pass(self):
        queue_name = "message_pass"
        client_id = "message_pass"
        kube_add = "localhost:50000"
        queue = MessageQueue(queue_name, client_id, kube_add)
        mm = []

        queuePolicy = QueueMessagePolicy(DelaySeconds=3)
        message = create_queue_message(
            "queueName {}".format(0),
            "some-simple_queue-queue-message".encode('UTF-8'), queuePolicy)
        mm.append(message)

        queuePolicy2 = QueueMessagePolicy(DelaySeconds=5)
        message2 = create_queue_message(
            "queueName {}".format(1),
            "some-simple_queue-queue-message".encode('UTF-8'), queuePolicy2)
        mm.append(message2)
        queue.send_queue_messages_batch(mm)

        res = queue.receive_queue_messages()
        self.assertFalse(res.is_error)
        self.assertEqual(0, len(res.messages))
        time.sleep(3.0)
        res = queue.receive_queue_messages()
        self.assertFalse(res.is_error)
        self.assertEqual(1, len(res.messages))
        time.sleep(2.0)
        res = queue.receive_queue_messages()
        self.assertFalse(res.is_error)
        self.assertEqual(1, len(res.messages))
Beispiel #3
0
def send_message_to_a_queue_with_delay(queue_name, client_id, kube_add,
                                       max_number_messages, max_timeout):
    queue = MessageQueue(queue_name, client_id, kube_add, max_number_messages,
                         max_timeout)
    policy = QueueMessagePolicy()
    policy.DelaySeconds = 5
    message = create_queue_message(
        "someMeta", "some-simple_queue-queue-message".encode('UTF-8'), policy)
    queue_send_message_to_queue_with_delay_response = queue.send_queue_message(
        message)
    print("finished sending message to queue with delay answer: {} ".format(
        queue_send_message_to_queue_with_delay_response))
Beispiel #4
0
def send_message_to_a_queue_with_deadletter_queue(queue_name, client_id,
                                                  kube_add,
                                                  max_number_messages,
                                                  max_timeout):
    queue = MessageQueue(queue_name, client_id, kube_add, max_number_messages,
                         max_timeout)
    policy = QueueMessagePolicy()
    policy.MaxReceiveCount = 3
    policy.MaxReceiveQueue = "DeadLetterQueue"
    message = create_queue_message(
        "someMeta", "some-simple_queue-queue-message".encode('UTF-8'), policy)
    queue_send_message_to_queue_with_deadletter_response = queue.send_queue_message(
        message)
    print(
        "finished sending message to queue with deadletter answer: {} ".format(
            queue_send_message_to_queue_with_deadletter_response))
Beispiel #5
0
from kubemq.grpc import QueueMessagePolicy
from kubemq.queue.message_queue import MessageQueue

from kubemq.queue.message import Message


def create_queue_message(meta_data, body, policy=None):
    message = Message()
    message.metadata = meta_data
    message.body = body
    message.tags = [
        ('key', 'value'),
        ('key2', 'value2'),
    ]
    message.attributes = None
    message.policy = policy
    return message


if __name__ == "__main__":
    channel = "queues.dead-letter"
    queue = MessageQueue(channel, "python-sdk-cookbook-queues-dead-letter-client", "localhost:50000")
    policy = QueueMessagePolicy()
    policy.MaxReceiveCount = 3
    policy.MaxReceiveQueue = "DeadLetterQueue"
    message = create_queue_message("some-metadata", "some-simple-queue-dead-letter-message".encode('UTF-8'), policy)
    queue_send_message_to_queue_with_deadletter_response = queue.send_queue_message(message)
    print("finished sending message to queue with dead-letter answer: {} ".format(
        queue_send_message_to_queue_with_deadletter_response))
Beispiel #6
0
    message.metadata = meta_data
    message.body = body
    message.tags = [
        ('key', 'value'),
        ('key2', 'value2'),
    ]
    message.attributes = None
    message.policy = policy
    return message


if __name__ == "__main__":
    channel = "queues.delayed"
    queue = MessageQueue(channel, "python-sdk-cookbook-queues-delayed-client", "localhost:50000")
    queuePolicy = QueueMessagePolicy(
        DelaySeconds=10
    )
    message = create_queue_message("queueName {}".format(channel),
                                   "some-simple-queue-delayed-message-1".encode('UTF-8'),queuePolicy)
    try:
        sent = queue.send_queue_message(message)
        if sent.is_error:
            print('message enqueue error, error:' + sent.error)
        else:
            print('Send to Queue')
    except Exception as err:
        print('message enqueue error, error:%s' % (
            err
        ))

    queue = MessageQueue(channel, "python-sdk-cookbook-queues-delayed-client-receiver", "localhost:50000", 2, 1)
Beispiel #7
0
    message.body = body
    message.tags = [
        ('key', 'value'),
        ('key2', 'value2'),
    ]
    message.attributes = None
    message.policy = policy
    return message


if __name__ == "__main__":
    channel = "queues.expiration"
    queue_sender = MessageQueue(
        channel, "python-sdk-cookbook-queues-expiration-client",
        "localhost:50000")
    policy = QueueMessagePolicy()
    policy.ExpirationSeconds = 5
    queue_message = create_queue_message(
        "queueName {}".format(channel),
        "some-simple-queue-expiration-message-1".encode('UTF-8'), policy)
    try:
        sent = queue_sender.send_queue_message(queue_message)
        if sent.is_error:
            print('message enqueue error, error:' + sent.error)
        else:
            print('Send to Queue')
    except Exception as err:
        print('message enqueue error, error:%s' % (err))

    queue_receiver = MessageQueue(
        channel, "python-sdk-cookbook-queues-expiration-client-receiver",