Skip to main content

merupakan package khusus django untuk keperluan berkomunikasi dengan rabbitmq

Quick start

  1. Tambahkan “aiga_amqp” ke INSTALLED_APPS pada file settings.py:

    INSTALLED_APPS = [
        ...
        'aiga_amqp',
    ]

A.1 Message Sender

Berikut contoh kode untuk mengirim message:

from aiga_amqp.core import send_queue

send_queue('nama channel', message='ini pesan')

A.2 Compete Consumer

Berikut merupakan langkah untuk consume antrian message secara “compete” atau bergantian.

  1. Pada folder app yang anda inginkan, tambahkan file consumer.py

  2. Pada file consumer.py buat function untuk menangani message seperti contoh dibawah ini:

    def consumer(channel, method, properties, body):
        print('saya telah baru saja melakukan sesuatu hal yang penting disini ...')
  3. Pada file apps.py override method ready dan lakukan perintah seperti contoh berikut untuk mengeksekusi consumer.py:

    from django.apps import AppConfig
    
    class ExampleConfig(AppConfig):
        default_auto_field = 'django.db.models.BigAutoField'
        name = 'example'
    
        def ready(self) -> None:
            from aiga_amqp.core import AMQPListener
            from .consumer import consumer
            listener = AMQPListener()
            listener.consume(consumer, channel_name='your channel name')
  1. Jalankan django

B.1 Publish Message

segera

B.2 Subscribe Message

segera

Settings Variable

Terdapat beberapa variable yang bisa digunakan pada settings.py beserta default value nya:

AIGA_AMQP = {
    'HOST' : 'localhost',   //alamat host dari rabbitmq
    'PORT' : 5672,          //port dari rabbitmq
    'CREDENTIAL' : False,   //set menjadi True jika menggunakan USERNAME dan PASSWORD
    'USERNAME' : None,      //username untuk mengakses rabbitmq
    'PASSWORD' : None,      //password untuk mengakses rabbitmq
    'HEARTBEAT' : 600,
    'TIMEOUT' : 300
}

Metadata

Release files for aiga-django-amqp 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiga-django-amqp 0.0.2
File Size Uploaded
aiga-django-amqp-0.0.2.tar.gz 4.6 kB Details

Release files / aiga-django-amqp-0.0.2.tar.gz

Download URL aiga-django-amqp-0.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bb8a8e79b6bbea21891b18ae78e1006c013b7d994674f18567bab6c6979cd6a6
BLAKE2b-256 checksum
How to use checksums
8cb4d37879eb07c6dbaffd8a90ce9caf3466d5bd6b7a4fbc94214f28fe7c1fa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page