0

My configuration: Running qpidd on host: 192.168.80.81 with following exchanges (qpid-config exchanges):

Type      Exchange Name       Attributes
==================================================
direct                        --replicate=none
direct    amq.direct          --durable --replicate=none
fanout    amq.fanout          --durable --replicate=none
headers   amq.match           --durable --replicate=none
topic     amq.topic           --durable --replicate=none
direct    qmf.default.direct  --replicate=none
topic     qmf.default.topic   --replicate=none
topic     qpid.management     --replicate=none

I have multiple producers publishing to the topics like amq.topic/com.product.sample1, amq.topic/com.product.sample2, you get the pattern.

I can receive all messages from the producers by running qpid-receive -b 192.168.80.81 -a amq.topic/com.product.sample1 -f on the commandline.

But when it comes to implementing this in Python using the python-qpid-proton library (version 0.35.0) it wont work as needed. This is my python file to receive messages on a specific topic:

from proton.handlers import MessagingHandler
from proton.reactor import Container

broker_url = "192.168.80.81:5672"
topic = "amq.topic/com.product.sample"


class Client(MessagingHandler):
    def __init__(self, broker_url, topic):
        super(Client, self).__init__()
        self.broker_url = broker_url
        self.topic = topic

    def on_start(self, event):
        conn = event.container.connect(self.broker_url)
        self.receiver = event.container.create_receiver(
            conn, self.topic, dynamic=True)

    def on_message(self, event):
        print(event.message.body)


Container(Client(broker_url, topic)).run()

Can anyone help me and point me to where my mistake is? Help is much appreciated!

Andreas
  • 31
  • 4

1 Answers1

0

Answered here: https://issues.apache.org/jira/browse/PROTON-2469

The issue here is the broker. It does not recognise amq.topic/com.product.sample. It does however support the subject binding filter. To do so you would use something like:

from proton import Described, symbol
from proton.handlers import MessagingHandler
from proton.reactor import Container, Filter

broker_url = "192.168.80.81:5672"
topic = "amq.topic"

class SubjectFilter(Filter):
    def __init__(self, value):
        super(SubjectFilter, self).__init__(\{symbol('subject-filter'): Described(symbol('apache.org:legacy-amqp-topic-binding:string'), value)})

class Client(MessagingHandler):
    def __init__(self, broker_url, topic):
        super(Client, self).__init__()
        self.broker_url = broker_url
        self.topic = topic

    def on_start(self, event):
        conn = event.container.connect(self.broker_url)
        self.receiver = event.container.create_receiver(
            conn, self.topic, options=SubjectFilter("com.product.sample"))

    def on_message(self, event):
        print(event.message.body)

Container(Client(broker_url, topic)).run()
Andreas
  • 31
  • 4