Exemple #1
0
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

from __future__ import print_function

import sys

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

from proton.tracing import init_tracer

tracer = init_tracer("receive")

class ReceiveHandler(MessagingHandler):
    def __init__(self, conn_url, address, desired):
        super(ReceiveHandler, self).__init__()

        self.conn_url = conn_url
        self.address = address

        self.desired = desired
        self.received = 0

    def on_start(self, event):
        conn = event.container.connect(self.conn_url)
        event.container.create_receiver(conn, self.address)
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
import optparse
from opentracing import tags

from client_common import Client

from proton.reactor import Container

from proton.tracing import init_tracer

tracer = init_tracer('client')

REQUESTS = [
    "Twas brillig, and the slithy toves", "Did gire and gymble in the wabe.",
    "All mimsy were the borogroves,", "And the mome raths outgrabe."
]

parser = optparse.OptionParser(
    usage="usage: %prog [options]",
    description="Send requests to the supplied address and print responses.")
parser.add_option("-a",
                  "--address",
                  default="localhost:5672/examples",
                  help="address to which messages are sent (default %default)")
opts, args = parser.parse_args()
Exemple #3
0
# specific language governing permissions and limitations
# under the License.
#

from __future__ import print_function

import sys

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

from opentracing import tags
from proton.tracing import init_tracer

tracer = init_tracer("send")

class SendHandler(MessagingHandler):
    def __init__(self, conn_url, address, message_body):
        super(SendHandler, self).__init__()

        self.conn_url = conn_url
        self.address = address

        try:
            self.message_body = unicode(message_body)
        except NameError:
            self.message_body = message_body

    def on_start(self, event):
        conn = event.container.connect(self.conn_url)
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

import optparse

from proton import Message, Url
from proton.handlers import MessagingHandler
from proton.reactor import Container
from proton.tracing import init_tracer

tracer = init_tracer('server')


class Server(MessagingHandler):
    def __init__(self, url, address):
        super(Server, self).__init__()
        self.url = url
        self.address = address

    def on_start(self, event):
        print("Listening on", self.url)
        self.container = event.container
        self.conn = event.container.connect(self.url)
        self.receiver = event.container.create_receiver(self.conn, self.address)
        self.server = self.container.create_sender(self.conn, None)
# specific language governing permissions and limitations
# under the License.
#

import collections
import optparse
import uuid

from opentracing import follows_from

from proton import Endpoint
from proton.handlers import MessagingHandler
from proton.reactor import Container
from proton.tracing import init_tracer

tracer = init_tracer('broker')

class Queue(object):
    def __init__(self, dynamic=False):
        self.dynamic = dynamic
        self.queue = collections.deque()
        self.consumers = []

    def subscribe(self, consumer):
        self.consumers.append(consumer)

    def unsubscribe(self, consumer):
        """
        :return: True if the queue is to be deleted
        """
        if consumer in self.consumers: