0

Below is my listener class with the subscriber

import os
import time
import stomp

def connect_and_subscribe(conn):
    conn.connect('guest', 'guest', wait=True)
    conn.subscribe(destination='/queue/test', id=1, ack='auto')

class MyListener(stomp.ConnectionListener):
    def __init__(self, conn):
        self.conn = conn

    def on_error(self, frame):
        print('received an error "%s"' % frame.body)

    def on_message(self, frame):
        print('received a message "%s"' % frame.body)
        for x in range(10):
            print(x)
            time.sleep(1)
        print('processed message')

    def on_disconnected(self):
        print('disconnected')
        connect_and_subscribe(self.conn)

conn = stomp.Connection([('localhost', 62613)], heartbeats=(4000, 4000))
conn.set_listener('', MyListener(conn))
connect_and_subscribe(conn)
time.sleep(60)
conn.disconnect()

Below is my producer code

import stomp
conn = stomp.Connection([('localhost', 62613)])
conn.connect('guest', 'guest', wait=True)
result = conn.send('/queue/test', 'test message')

I need to get the result/status of sent data, in order use that status to retry in case of failover

I know this details can be received in on_send listener

on_send SEND {'content-length': 5, 'destination': '/queue/test'} b'a test message'

But for this I need to create a class inheriting ConnectionListener class, and add method on_send Listener to get the response.

Is it possible to get the response without creating any class?

Thanks

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
Umesh K
  • 51
  • 1
  • 2
  • What broker are you using? – Justin Bertram Oct 13 '22 at 11:56
  • I'm using ActiveMQ Artemis. https://activemq.apache.org/components/artemis/ – Umesh K Oct 13 '22 at 12:55
  • @JustinBertram do you have any suggestion on this? – Umesh K Oct 18 '22 at 09:37
  • I don't have anything conclusive as the API documentation isn't very good. However, my suspicion is that the `send` method is synchronous so that if there was any problem it would be reported back to you directly without needing to create any kind of callback/listener. – Justin Bertram Oct 18 '22 at 14:22
  • Documentation you are referring to stomp.py docs? Because I'm able to achieve this using php-stomp. `$success = PhpStomp::send_message($topic, $content, $headers);` `$status = $success ? "SUCCESS" : "FAIL";` – Umesh K Oct 18 '22 at 14:35
  • Yes, I was referring to the [stomp.py documentation](http://jasonrbriggs.github.io/stomp.py/index.html). The behavior of the php-stomp client isn't really relevant as it's a completely different implementation. – Justin Bertram Oct 18 '22 at 14:43

0 Answers0