def selector(self): """ Creates a selector expression of the offset """ if isinstance(self.value, datetime.datetime): epoch = datetime.datetime.utcfromtimestamp(0) milli_seconds = timestamp( (self.value - epoch).total_seconds() * 1000.0) return Selector(u"amqp.annotation.x-opt-enqueued-time > '" + str(milli_seconds) + "'") elif isinstance(self.value, timestamp): return Selector(u"amqp.annotation.x-opt-enqueued-time > '" + str(self.value) + "'") else: operator = ">=" if self.inclusive else ">" return Selector(u"amqp.annotation.x-opt-offset " + operator + " '" + utf82unicode(self.value) + "'")
def start(self, client): self.client = client self.iteration += 1 link_name = "py-receiver-%s-%d" % (self.name, self.iteration) selector = Selector(u"amqp.annotation.x-opt-offset > '" + self.offset + "'") client.create_receiver(client.shared_connection, self.source, name=link_name, handler=self, options=selector)
def __init__(self, urls, address, callback, data=None, ssl_domain=None, selector=None, subscription_name=None, **super_handler_kwargs): """Initialize handler :param list urls: list of URLs of brokers. Each of URL could in format ``hostname[:port]``. :param str address: address from which to receive messages. :param callable callback: user-defined method to be called when a message is received. :param data: user data that will be passed to ``callback`` method. It is optional. :param ssl_domain: object containing SSL certificate and private key. It is optional. If omitted, do not connect to broker over SSL. :type ssl_domain: ``proton.SSLDomain``. :param str selector: filter string used to select messages that meet specific criteria. For a detailed syntax infomration of a usable selector, please refer to https://activemq.apache.org/selectors.html. It is optional. If omitted, every message sent to ``address`` will arrive at and be passed to ``callback``. :param str subscription_name: name to use to identify the durable subscription. It will also be used as the client ID. If it is None, the subscription will be non-durable, and the client ID will be random. :param dict super_handler_kwargs: parameters that super class ``MessagingHandler`` accepts. If manual control of accepting a mesaging is required, set ``auto_accept`` to False. """ super(ReceiverHandler, self).__init__(**super_handler_kwargs) self.auto_accept = super_handler_kwargs.get('auto_accept', True) self.urls = urls if selector is None: self.selector = None else: self.selector = Selector(selector) self.ssl_domain = ssl_domain self.callback = callback self.data = data self.address = address self.subscription_name = subscription_name self.result = None
def connect_iothub(event): # -1 = beginning # @latest = only new messages offset = "@latest" selector = Selector(u"amqp.annotation.x-opt-offset > '" + offset + "'") azure_config = configp['azure'] amqp_url = azure_config['iothub_amqp_url'] partition_name = azure_config['iothub_partition_name'] while True: try: conn = event.container.connect(amqp_url, allowed_mechs="PLAIN MSCBS", session_policy=None, shared_connection=None) event.container.create_receiver( conn, partition_name + "/ConsumerGroups/$default/Partitions/0", options=selector) event.container.create_receiver( conn, partition_name + "/ConsumerGroups/$default/Partitions/1", options=selector) event.container.create_receiver( conn, partition_name + "/ConsumerGroups/$default/Partitions/2", options=selector) event.container.create_receiver( conn, partition_name + "/ConsumerGroups/$default/Partitions/3", options=selector) except Exception: logger.exception("Error connecting to IotHub. Retrying in 30sec") time.sleep(30) continue else: break
def on_start(self, event): conn = event.container.connect(self.url) event.container.create_receiver(conn, self.url.path, options=Selector("colour = 'green'"))
def test_non_unicode_selector(self): assert Selector(b"Hello").filter_set[symbol( 'selector')].value == u"Hello"
def on_start(self, event): conn = event.container.connect("localhost:5672") event.container.create_receiver(conn, "examples", options=Selector(u"colour = 'green'"))