activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neil Pritchard <Neil.Pritch...@securetrading.com>
Subject Individual acknowledge in pyactivemq
Date Tue, 14 Sep 2010 13:17:08 GMT
Hi All,

I'm using pyactivemq as both a producer and consumer of messages which are being brokered
by ActiveMQ 5.3.2.  In the past I used python stompy to produce messages and java ActiveMQ
to consume them.  I need to set a prefetch policy of 1 messgae at a time and more importantly
use individual acknowledge (or client acknowledge) but can't find any example of how to acknowledge
the message in pyactivemq, also the activeMQ log (set to debug) indicates that the messages
are being consumed regardless.  Can anyone tell me how to set the acknowledgement mode properly
and how to acknowledge a message.  When I try to acknowledge, Python can't find the Acknowledge()
method.

Many thanks,

Neil

Here's my consumer:....

#!/usr/bin/env python

import cpickle as pickle
import Queue
import pyactivemq
from pyactivemq import ActiveMQConnectionFactory
from pyactivemq import AcknowledgeMode

class MessageListener(pyactivemq.MessageListener):
    def __init__(self, name, queue):
        pyactivemq.MessageListener.__init__(self)
        self.name = name
        self.queue = queue

    def onMessage(self, message):
        self.queue.put('%s got: %s' % (self.name, message.text))

f = ActiveMQConnectionFactory('failover:(tcp://localhost:61616)?wireFormat=openwire')
conn = f.createConnection()
consumer_session = conn.createSession(AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE)
myqueue = consumer_session.createQueue('NOTIFICATIONS.QUEUE')
queue = Queue.Queue(0)

session = conn.createSession(AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE)
consumer = session.createConsumer(myqueue)
listener = MessageListener('consumer', queue)
consumer.messageListener = listener

conn.start()
while queue:
    message = queue.get(block=True)
    message = message[14:]
    notificationDict = pickle.loads(message)
    print notificationDict
    acknowledge()

conn.close()


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message