Skip to content

Commit

Permalink
Merge pull request #21 from daveads/pulsar_script_integration
Browse files Browse the repository at this point in the history
Add Pulsar start and stop scripts with GitHub Actions integration #cl…
  • Loading branch information
gemanor authored Sep 25, 2024
2 parents 17d5f9d + ae0114d commit 0fb7936
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 16 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,22 @@ jobs:
with:
python-version: "${{ matrix.python-version }}"

# Install Docker Compose if it's not available by default
- name: Set up Docker Compose
run: sudo apt-get install docker-compose -y

# Start Pulsar using Docker Compose
- name: Start Pulsar
run: docker-compose up -d pulsar
run: "scripts/start_pulsar"


- name: Wait for Pulsar
run: |
timeout 300 bash -c '
until curl -s http://localhost:8080/admin/v2/brokers/healthcheck; do
echo "Waiting for Pulsar to be ready..."
sleep 5
done
echo "pulsar is ready"
'
run: "scripts/wait_for_pulsar"

- name: "Install dependencies"
run: "scripts/install"

# - name: "Run linting checks"
# run: "scripts/check"

- name: "Build package & docs"
run: "scripts/build"

- name: "Run tests"
run: "scripts/test"

Expand All @@ -88,4 +79,5 @@ jobs:

# Stop the Pulsar container after all tests are complete
- name: Stop Pulsar
run: docker-compose down
if: always() # This ensures the step runs even if previous steps fail
run: "scripts/stop_pulsar"
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a fork of [encode/broadcaster](https://github.com/encode/broadcaster).
Broadcaster helps you develop realtime streaming functionality by providing
a simple broadcast API onto a number of different backend services.

It currently supports [Redis PUB/SUB](https://redis.io/topics/pubsub), [Apache Kafka](https://kafka.apache.org/), and [Postgres LISTEN/NOTIFY](https://www.postgresql.org/docs/current/sql-notify.html), plus a simple in-memory backend, that you can use for local development or during testing.
It currently supports [Redis PUB/SUB](https://redis.io/topics/pubsub), [Apache Kafka](https://kafka.apache.org/), [Apache Pulsar](https://pulsar.apache.org/) and [Postgres LISTEN/NOTIFY](https://www.postgresql.org/docs/current/sql-notify.html), plus a simple in-memory backend, that you can use for local development or during testing.

<img src="https://raw.githubusercontent.com/encode/broadcaster/master/docs/demo.gif" alt='WebSockets Demo'>

Expand Down Expand Up @@ -108,6 +108,35 @@ KAFKA_SSL_KEY_PASSWORD=None # Private key password
For full details refer to the (AIOKafka options)[https://aiokafka.readthedocs.io/en/stable/api.html#producer-class] where the variable name matches the capitalised env var with an additional `KAFKA_` prefix.
For SSL properties see (AIOKafka SSL Context)[https://aiokafka.readthedocs.io/en/stable/api.html#aiokafka.helpers.create_ssl_context].


## Apache Pulsar

Support for Apache Pulsar, a distributed messaging system, has been added.

To use Pulsar as a backend, ensure you have the necessary package installed:

```bash
pip install permit-broadcaster[pulsar]
```

You will also need a running Pulsar instance. Follow the [official Pulsar installation guide](https://pulsar.apache.org/docs/3.3.x/getting-started-home/) for detailed setup instructions. You can also start Pulsar via Docker using the provided `docker-compose.yaml` file in the repository:

```bash
docker-compose up pulsar
# The same applies for other services...
```

**In the Available backends section, add:**
```python
Broadcast("pulsar://localhost:6650")
```

Ensure you have a Pulsar server running before executing this example.

### Updated Changes
* **Added Pulsar**: Apache Pulsar is now available as a backend in Broadcaster.


## Where next?

At the moment `broadcaster` is in Alpha, and should be considered a working design document.
Expand Down
16 changes: 16 additions & 0 deletions scripts/start_pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Install Docker Compose if it's not available
if ! command -v docker-compose &> /dev/null; then
echo "Docker Compose not found. Installing..."
sudo apt-get update
sudo apt-get install -y docker-compose
else
echo "Docker Compose is already installed."
fi

# Start Pulsar using Docker Compose
echo "Starting Pulsar..."
docker-compose up -d pulsar

echo "Pulsar startup complete."
17 changes: 17 additions & 0 deletions scripts/stop_pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash


echo "Stopping Pulsar container..."

# Stop and remove containers defined in docker-compose.yml
if docker-compose down; then
echo "Pulsar container have been stopped and removed successfully."
else
echo "Error: Failed to stop Pulsar containers. Please check Docker Compose configuration."
exit 1
fi

# Optional: Remove volumes
# docker-compose down -v

echo "Cleanup complete."
19 changes: 19 additions & 0 deletions scripts/wait_for_pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

MAX_RETRIES=60
RETRY_INTERVAL=5
HEALTH_CHECK_URL="http://localhost:8080/admin/v2/brokers/healthcheck"

echo "Waiting for Pulsar to be ready..."

for i in $(seq 1 $MAX_RETRIES); do
if curl -s "$HEALTH_CHECK_URL" > /dev/null; then
echo "Pulsar is ready!"
exit 0
fi
echo "Attempt $i/$MAX_RETRIES: Pulsar is not ready yet. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
done

echo "Error: Pulsar did not become ready within the allocated time."
exit 1

0 comments on commit 0fb7936

Please sign in to comment.