Skip to content

Commit

Permalink
feat(README): update docs to support all functions in queue (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
tavallaie authored May 16, 2024
1 parent 422d0a2 commit c8e6acd
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions tembo-pgmq-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Installation

Install with `pip` from pypi.org
Install with `pip` from pypi.org:

```bash
pip install tembo-pgmq-python
Expand All @@ -14,58 +14,80 @@ Postgres running the [Tembo PGMQ extension](https://github.com/tembo-io/tembo/tr

## Usage

## Start a Postgres Instance with the Tembo extension installed
### Start a Postgres Instance with the Tembo extension installed

```bash
docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 quay.io/tembo/pgmq-pg:latest
```

Initialize a connection to Postgres
### Initialize a connection to Postgres

```python
from tembo_pgmq_python import PGMQueue, Message

queue = PGMQueue(host="0.0.0.0")
```

Create a queue (or a partitioned queue)
### Create a queue

```python
queue.create_queue("my_queue")
# queue.create_partitioned_queue("my_partitioned_queue", partition_size=10000)
```
### or a partitioned queue
```python
queue.create_partitioned_queue("my_partitioned_queue", partition_size=10000)
```
### Send a message

```python
msg_id: int = queue.send("my_queue", {"hello": "world"})
```

Send a message
### Send a batch of messages

```python
msg_id: int = queue.send("my_queue", {"hello": "world"})
msg_ids: list[int] = queue.send_batch("my_queue", [{"hello": "world"}, {"foo": "bar"}])
```

Read a message, set it invisible for 30 seconds.
### Read a message, set it invisible for 30 seconds

```python
read_message: Message = queue.read("my_queue", vt=30)
print(read_message)
```

Archive the message after we're done with it. Archived messages are moved to an archive table.
### Read a batch of messages

```python
read_messages: list[Message] = queue.read_batch("my_queue", vt=30, batch_size=5)
for message in read_messages:
print(message)
```

### Archive the message after we're done with it. Archived messages are moved to an archive table

```python
archived: bool = queue.archive("my_queue", read_message.msg_id)
```

Delete a message completely.
### Delete a message completely

```python
msg_id: int = queue.send("my_queue", {"hello": "world"})
read_message: Message = queue.read("my_queue")
deleted: bool = queue.delete("my_queue", read_message.msg_id)
```

Pop a message, deleting it and reading it in one transaction.
### Pop a message, deleting it and reading it in one transaction

```python
popped_message: Message = queue.pop("my_queue")
print(popped_message)
```

### Purge all messages from a queue

```python
purged_count: int = queue.purge("my_queue")
print(f"Purged {purged_count} messages from the queue.")
```

0 comments on commit c8e6acd

Please sign in to comment.