On 20/01/17 23:56, Greg Oliver wrote:
Using Python. Proton 0.16.0.
Would like to receive messages from an Azure Event Hub using proton. Need to
set message filters based on offset or timestamp.
I've read about adding annotations to a request such as: x-opt-offset,
x-opt-enqueued-time, x-opt-sequence-number.
But no idea how to set these values, especially using Python.
Attached is a simple example of setting a selector filter. You can
replace the actual selector string with something that Event Hubs will
understand e.g. from Ken's link, ”amqp.annotation.x-opt-offset > '100'”.
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#
from __future__ import print_function
from proton.reactor import Container, Selector
from proton.handlers import MessagingHandler
class Recv(MessagingHandler):
def __init__(self):
super(Recv, self).__init__()
def on_start(self, event):
conn = event.container.connect("localhost:5672")
event.container.create_receiver(conn, "myqueue", options=Selector("colour = 'green'"))
def on_message(self, event):
print(event.message.body)
try:
Container(Recv()).run()
except KeyboardInterrupt: pass
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]