// Module included in the following assemblies:
//
// assembly-connecting-applications.adoc

[id='ref-python-example-{context}']

= {ClientAmqpPythonName} example

You can use the following {ClientAmqpPythonName} example to connect your application to {ProductName}. This example assumes you have created an address of type `queue` named `myqueue`.

[source,python,options="nowrap",subs="attributes"]
----
from __future__ import print_function, unicode_literals
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container

class HelloWorld(MessagingHandler):
    def __init__(self, server, address):
        super(HelloWorld, self).__init__()
        self.server = server
        self.address = address

    def on_start(self, event):
        conn = event.container.connect(self.server)
        event.container.create_receiver(conn, self.address)
        event.container.create_sender(conn, self.address)

    def on_sendable(self, event):
        event.sender.send(Message(body="Hello World!"))
        event.sender.close()

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

Container(HelloWorld("amqps://_messaging-route-hostname_:443", "myqueue")).run()
----

== Known issue with creating a subscriber on a hierarchical topic

A known issue exists where creating a subscriber on a hierarchical topic in {ProductName} causes the broker to instead create it as a competing consumer (handling the address like a queue rather than a topic).

The workaround for this issue involves setting the capability `"topic"` in the source.

.Procedure

. In the `simple_recv.py` file, modify the `from proton.reactor import Container` to add the `ReceiverOption`:

[source,python,options="nowrap",subs="+quotes,attributes"]
----
class CapabilityOptions(ReceiverOption):
    def apply(self, receiver):
        receiver.source.capabilities.put_object(symbol("topic"))
----

. Modify the following line to add `options=CapabilityOptions()`:

[source,python,options="nowrap",subs="+quotes,attributes"]
----
def on_start(self, event):
        event.container.create_receiver(conn, self.address, options=CapabilityOptions())
----

