Skip to content

Commit

Permalink
Added ttl exampels
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Apr 13, 2019
1 parent 24dd2de commit 3833090
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/consume_queue_until_empty.py
Expand Up @@ -2,7 +2,7 @@

from amqpstorm import Connection

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def consume_until_queue_is_empty():
Expand Down
27 changes: 27 additions & 0 deletions examples/create_queue_with_a_ttl_on_messages.py
@@ -0,0 +1,27 @@
import logging

from amqpstorm import Connection
from amqpstorm import Message

logging.basicConfig(level=logging.INFO)


def publish_message(channel, body, queue):
# Create a message.
message = Message.create(channel, body)

# Publish the message to a queue.
message.publish(queue)


if __name__ == '__main__':
with Connection('127.0.0.1', 'guest', 'guest') as CONNECTION:
with CONNECTION.channel() as CHANNEL:
# Declare the Queue, 'simple_queue' with a message ttl of 6000ms.
CHANNEL.queue.declare('simple_ttl_queue', arguments={
'x-message-ttl': 6000,
})

# Publish the message to a queue called, 'simple_queue' with an
# expiration set to 6000ms.
publish_message(CHANNEL, 'Hello World', 'simple_ttl_queue')
26 changes: 26 additions & 0 deletions examples/publish_message_with_expiration.py
@@ -0,0 +1,26 @@
import logging

from amqpstorm import Connection
from amqpstorm import Message

logging.basicConfig(level=logging.INFO)


def publish_message(channel, body, queue, expiration="600"):
# Create the message with a expiration (time to live).
message = Message.create(channel, body,
properties={"expiration": expiration})

# Publish the message to a queue.
message.publish(queue)


if __name__ == '__main__':
with Connection('127.0.0.1', 'guest', 'guest') as CONNECTION:
with CONNECTION.channel() as CHANNEL:
# Declare the Queue, 'simple_queue'.
CHANNEL.queue.declare('simple_queue')

# Publish the message to a queue called, 'simple_queue' with an
# expiration set to 6000ms.
publish_message(CHANNEL, 'Hello World', 'simple_queue', "6000")
2 changes: 1 addition & 1 deletion examples/robust_consumer.py
Expand Up @@ -7,7 +7,7 @@
import amqpstorm
from amqpstorm import Connection

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)

LOGGER = logging.getLogger()

Expand Down
2 changes: 1 addition & 1 deletion examples/scalable_consumer.py
Expand Up @@ -8,7 +8,7 @@
import amqpstorm
from amqpstorm import Connection

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger()


Expand Down
2 changes: 1 addition & 1 deletion examples/scalable_rpc_server.py
Expand Up @@ -9,7 +9,7 @@
from amqpstorm import Connection
from amqpstorm import Message

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)

LOGGER = logging.getLogger()

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_consumer.py
Expand Up @@ -2,7 +2,7 @@

from amqpstorm import Connection

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def on_message(message):
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_generator_consumer.py
Expand Up @@ -2,7 +2,7 @@

from amqpstorm import Connection

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def start_consumer():
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_publisher.py
Expand Up @@ -3,7 +3,7 @@
from amqpstorm import Connection
from amqpstorm import Message

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def publish_message():
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_transaction_publisher.py
Expand Up @@ -3,7 +3,7 @@
from amqpstorm import Connection
from amqpstorm import Message

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def publish_messages():
Expand Down
2 changes: 1 addition & 1 deletion examples/ssl_with_context.py
Expand Up @@ -3,7 +3,7 @@

from amqpstorm import Connection

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def on_message(message):
Expand Down

0 comments on commit 3833090

Please sign in to comment.