Package: django-stomp
Django StompA simple implementation of STOMP with Django.In theory it can work with any broker which supports STOMP with none or minor adjustments.Installationpip install django_stompAdddjango_stompin yourINSTALLED_APPSand so be it.Configuration processNot yet fully available, but feel free to see our tests to get insights.ConsumerFirst you must create a function which receives an parameter of typedjango_stomp.services.consumer.Payload. Let's suppose the moduleapp.samplewith the following content:importloggingfromdjango_stomp.services.consumerimportPayloadlogger=logging.getLogger(__name__)defmy_honest_logic(payload:Payload)->None:logger.info("Yeah, I received a payload from django-stomp!")my_payload=payload.bodymy_header=payload.headersifmy_payload.get("my-dict-key"):payload.ack()else:logger.info("To DLQ!")payload.nack()Now you must provide broker connection details filling out the following parameters at least:STOMP_SERVER_HOSTSTOMP_SERVER_PORTSTOMP_USE_SSLAnd just create the job issuing the following command:pythonmanage.pypubsub"/queue/your-stuff"app.sample.my_honest_logicThat's it ✌️SettingsHere is a list of parameters that you can set in your Django project settings:STOMP_SERVER_HOSTThe hostname of the STOMP server.STOMP_SERVER_PORTThe STOMP server port used to allow STOMP connections.STOMP_SERVER_USERThe client username to connect to a STOMP server.STOMP_SERVER_PASSWORDThe client password to connect to a STOMP server.STOMP_USE_SSLSet toTrue, true, 1, T, t, Y or yin order to all STOMP connections use a SSL/TLS tunnel.STOMP_SERVER_STANDBY_HOSTThe hostname of the STOMP standby server.STOMP_SERVER_STANDBY_PORTThe STOMP standby server port used to allow STOMP connections.STOMP_SERVER_VHOSTThe virtual host used in the STOMP server.STOMP_SUBSCRIPTION_IDUsed to identify the subscription in the connection between client and server. See theSTOMP protocol specificationfor more information.STOMP_OUTGOING_HEARTBEATA positive integer to indicates what is the period (in milliseconds) the client will send a frame to the server
that indicates its still alive. Set to0to means that it cannot send any heart-beat frame. See theSTOMP
protocol specificationfor more information.
Defaults to 10000 ms.STOMP_INCOMING_HEARTBEATA positive integer to indicates what is the period (in milliseconds) the client will await for a server frame until
it assumes that the server is still alive. Set to0to means that it do not want to receive heart-beats. See
theSTOMP protocol specificationfor more
information. Defaults to 10000 ms.STOMP_WAIT_TO_CONNECTA positive integer to indicates how long it needs to await to try to reconnect if anExceptionin the listener
logic is not properly handled.STOMP_DURABLE_TOPIC_SUBSCRIPTIONSet toTrue, true, 1, T, t, Y or yin order to all STOMP topic subscription be durable. See theRabbitMQtake on it or theActiveMQfor more information.STOMP_LISTENER_CLIENT_IDA string that represents the client id for a durable subscriber or the listener prefix client id in a non-durable
subscription in ActiveMQ.STOMP_CORRELATION_ID_REQUIREDA flag that indicates ifcorrelation-idheader must be required or not. By default this flag is true (good practice
thinking in future troubleshooting).
Set toFalse, false, 0, F, f, N or nin order to allow consume messages withoutcorrelation-idheader. If it's
falsedjango-stompgenerates a correlation-id header for the message automatically.STOMP_PROCESS_MSG_ON_BACKGROUNDA flag to indicate if it should process a received message on background, enabling the broker-consumer communication
to still take place.
Set toTrue, true, 1, T, t, Y or yin order to have the message processing on background.STOMP_PROCESS_MSG_WORKERSOptional parameter that controls how many workers the pool that manage the background processing should create. If
defined, this parametermustbe an integer!STOMP_GRACEFUL_WAIT_SECONDSOptional parameter that controls how many seconds django-stomp will wait for a message to be processed. Defaults to 30 seconds. If defined, this parametermustbe an integer!STOMP_DEFAULT_EXCLUSIVE_QUEUEOptional parameter that defines if the default value ofexclusivequeue parameter will be True or False when creating a queue in RabbitMQ. The default value isFalse.TestsIn order to execute tests for ActiveMQ, execute the following:docker-composeup-dbroker-activemqOr for RabbitMQ:docker-composeup-dbroker-rabbitmqThen at last:pipenvruntoxDatabase connection management (applies to version >= 5.0.0)For every message that adjango-stompconsumer receives, it opens a new DB connection if it needs to, keeping it open until it exceeds the maximum age defined byCONN_MAX_AGEor when the connection becomes unusable.Known limitationsCurrently, we assume that all dead lettered messages are sent to a queue with the same name as its original
destination but prefixed withDLQ., i.e., if your queue is/queue/some-queue, the dead letter destination is
asssumed to be/queue/DLQ.some-queue.Be cautious with the heartbeat functionality! If your consumer is slow, it could prevent the client to receive
and process anyheart-beatframe sent by the server, causing the client to terminate the connection due to a false
positive heartbeat timeout. You can workaround it with theSTOMP_PROCESS_MSG_ON_BACKGROUNDparameter that uses a
thread pool to process the message.For the RabbitMQ users: thedjango-stomp consumeralways try to connect to adurable queue, so if your queue is not durable, the RabbitMQ broker
will not allow the subscription.For versions prior to 5.0.0: Any database connection management in the consumer side is up to its callback. If you have any long-running consumer that relies on a DB connection, be sure that you manage it properly, otherwise if a connection becomes unusable, you'll have to restart the consumer entirely just to setup a new DB connection.