RabbitMQ for Seismic Waveforms: Enabling Reliable Data Communication

Utpal Kumar   2 minute read      

Learn how to use RabbitMQ with Python to publish and consume seismic waveform messages reliably in real time for distributed seismology workflows.

Seismic data communication often needs reliable, near-real-time transfer between acquisition, processing, and alerting components. RabbitMQ is a robust and scalable message broker that helps decouple these components and move waveform messages safely across distributed systems.

In this post, we set up RabbitMQ for publishing seismic waveform data and subscribing to it in real time using Python and the pika client.

What is RabbitMQ?

RabbitMQ is an open-source message broker that implements AMQP (Advanced Message Queuing Protocol). It enables asynchronous communication by routing messages between producers and consumers through queues and exchanges.

This pattern is useful in seismology systems where data producers (stations, telemetry services, ingest pipelines) and data consumers (detectors, pickers, dashboards, archival services) should run independently.

Key Concepts

  • Producer: sends messages.
  • Queue: stores messages until consumed.
  • Consumer: receives and processes messages.
  • Exchange: routes messages to queues.
    • direct: routes using exact routing keys.
    • fanout: broadcasts to all bound queues.
    • topic: routes by wildcard routing patterns.
    • headers: routes by message headers.
  • Binding: rule that connects an exchange to a queue.

Set Up RabbitMQ

Requirements

  • Docker (optional, easiest for local setup)
  • Python 3.7+
  • pika Python library

Start RabbitMQ with Docker

docker run -d --hostname rabbit-host --name rabbitmq \
  -p 5672:5672 -p 15672:15672 rabbitmq:3-management
  • AMQP endpoint: localhost:5672
  • Management UI: http://localhost:15672 (default user/password: guest / guest)

Install Python Client

pip install pika

Producer: Publish Seismic Waveform Messages

Create producer.py:

import json
import pika


def publish_seismic_data(channel, queue_name, data):
    channel.basic_publish(
        exchange="",
        routing_key=queue_name,
        body=json.dumps(data),
    )
    print(f"[x] Sent: {data}")


connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost"))
channel = connection.channel()

queue_name = "seismic_data"
channel.queue_declare(queue=queue_name)

seismic_data = {
    "station": "ABC",
    "timestamp": "2024-06-16T12:00:00Z",
    "sampling_rate_hz": 100,
    "amplitude": [0.1, 0.3, -0.2, 0.4],
}

publish_seismic_data(channel, queue_name, seismic_data)
connection.close()

Consumer: Receive and Process in Real Time

Create consumer.py:

import json
import pika


def callback(ch, method, properties, body):
    data = json.loads(body)
    print(f"[x] Received: {data}")
    # Add detection/picking/alert logic here.


connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost"))
channel = connection.channel()

queue_name = "seismic_data"
channel.queue_declare(queue=queue_name)

channel.basic_consume(
    queue=queue_name,
    on_message_callback=callback,
    auto_ack=True,
)

print("[*] Waiting for messages. To exit press CTRL+C")
channel.start_consuming()

Run Producer and Consumer

  1. Start RabbitMQ.
  2. Start consumer first:
python consumer.py
  1. Publish data:
python producer.py

The consumer should print received waveform messages as they arrive.

Optional: Route by Topic Exchange

If you want routing by message type or station family, use a topic exchange.

channel.exchange_declare(exchange="seismic_exchange", exchange_type="topic")
channel.queue_bind(
    exchange="seismic_exchange",
    queue=queue_name,
    routing_key="seismic.#",
)

Publish with a routing key:

channel.basic_publish(
    exchange="seismic_exchange",
    routing_key="seismic.waveform",
    body=json.dumps(seismic_data),
)

Practical Seismology Use Cases

  • Real-time earthquake monitoring pipelines.
  • Distributed waveform processing across worker services.
  • Alerting and notification systems.
  • Reliable buffering before archival or downstream analytics.

Conclusion

RabbitMQ provides a reliable asynchronous backbone for seismic waveform communication. By separating producers from consumers and supporting flexible routing, it improves scalability and fault tolerance in modern seismology workflows.

Disclaimer of liability

The information provided by the Earth Inversion is made available for educational purposes only.

Whilst we endeavor to keep the information up-to-date and correct. Earth Inversion makes no representations or warranties of any kind, express or implied about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services or related graphics content on the website for any purpose.

UNDER NO CIRCUMSTANCE SHALL WE HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE SITE OR RELIANCE ON ANY INFORMATION PROVIDED ON THE SITE. ANY RELIANCE YOU PLACED ON SUCH MATERIAL IS THEREFORE STRICTLY AT YOUR OWN RISK.