Search code examples
pythonactivemq-classicstomp

Producing persistent message using stompest for python


I am not able to send persistent message to AMQ queue using stompest and python.. Dont know what header to use??? Below is source code

from stompest.config import StompConfig
from stompest.sync import Stomp
import os

CONFIG = StompConfig('tcp://localhost:61613')
QUEUE = '/queue/myQueue'


if __name__ == '__main__':

    try:
        client = Stomp(CONFIG)
        client.connect({'login':'#####','passcode':'#####'})
        for i in range(10):
            msg="Test Message" +str(i)
            client.send(QUEUE,msg)
        client.disconnect()
    except Exception,e:
        print e

Solution

  • If you go persistent, you may also want to send you message in a transaction.

    with client.transaction(receipt='important') as transaction:
            client.send(QUEUE, 'test',{'persistent':'true', StompSpec.TRANSACTION_HEADER: transaction})
    

    This way, you can ensure all or none of a set of messages ends up on a queue. If there is an error raised within the transaction block, the message(s) won't be committed to the queue. The same goes for reading messages.