0
votes
  • Hi, I am using stomp.py module to send and receive messages from
    ActiveMQ using python.
  • While receiving messages listener will read multiple messages within the specified sleep time.
  • But I need to read only a single message. It's possible in java. How can I read a single message from ActiveMQ using STOMP?

Here is the listener script which I am testing,

import stomp
import time

class SampleListener(object):
  def on_message(self, headers, msg):
    print(msg)

conn = stomp.Connection([('localhost',61613)]) 
conn.set_listener('SampleListener', SampleListener()) 
conn.start() 
conn.connect() 
conn.subscribe(destination='queue_name', id=1, ack='auto')
time.sleep(10) # secs 
conn.disconnect()
1
Hi @Karthikeyan.. I am also trying to achieve the same scenario but using AWS Lambda Function, but I am receiving errors stating- "Unable to import module 'lambda_function': No module named 'stomp'" How can I add stomp dependency in my AWS Lambda function.asur
@Kally you need to bundle all the dependent modules to the zip file.Karthikeyan KR
Thanks @Karthikeyan I used your script but I feel, I am not receiving messages from MQ. Any suggestionsasur

1 Answers

1
votes

If you only want to read one message at a time with STOMP the only way to do that is to use an ack mode such as client or client-individual so that the client is sent new messages only when it has sent an explicit ACK for the one's that it has. This also would require setting the prefetch value to one so that the broker doesn't send a batch of messages to the client.

The STOMP Acknowledgement modes are defined in the spec here. The documentation for the broker's STOMP support is here. The client sets the prefetch using the header 'activemq.prefetchSize' on the SUBSCRIBE as listed in the ActiveMQ documentation.