Package qpid :: Package messaging :: Module util
[frames] | no frames]

Source Code for Module qpid.messaging.util

 1  # 
 2  # Licensed to the Apache Software Foundation (ASF) under one 
 3  # or more contributor license agreements.  See the NOTICE file 
 4  # distributed with this work for additional information 
 5  # regarding copyright ownership.  The ASF licenses this file 
 6  # to you under the Apache License, Version 2.0 (the 
 7  # "License"); you may not use this file except in compliance 
 8  # with the License.  You may obtain a copy of the License at 
 9  # 
10  #   http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, 
13  # software distributed under the License is distributed on an 
14  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
15  # KIND, either express or implied.  See the License for the 
16  # specific language governing permissions and limitations 
17  # under the License. 
18  # 
19   
20  """ 
21  Add-on utilities for the L{qpid.messaging} API. 
22  """ 
23   
24  from qpid.messaging import * 
25  from logging import getLogger 
26  from threading import Thread 
27   
28  log = getLogger("qpid.messaging.util") 
29   
30 -def auto_fetch_reconnect_urls(conn):
31 ssn = conn.session("auto-fetch-reconnect-urls") 32 rcv = ssn.receiver("amq.failover") 33 rcv.capacity = 10 34 35 def main(): 36 while True: 37 try: 38 msg = rcv.fetch() 39 except LinkClosed: 40 return 41 set_reconnect_urls(conn, msg) 42 ssn.acknowledge(msg, sync=False)
43 44 thread = Thread(name="auto-fetch-reconnect-urls", target=main) 45 thread.setDaemon(True) 46 thread.start() 47 48
49 -def set_reconnect_urls(conn, msg):
50 reconnect_urls = [] 51 urls = msg.properties["amq.failover"] 52 for u in urls: 53 # FIXME aconway 2012-06-12: Nasty hack parsing of the C++ broker's URL format. 54 if u.startswith("amqp:"): 55 for a in u[5:].split(","): 56 parts = a.split(":") 57 # Handle IPv6 addresses which have : in the host part. 58 port = parts[-1] # Last : separated field is port 59 host = ":".join(parts[1:-1]) # First : separated field is protocol, host is the rest. 60 reconnect_urls.append("%s:%s" % (host, port)) 61 conn.reconnect_urls = reconnect_urls 62 log.warn("set reconnect_urls for conn %s: %s", conn, reconnect_urls)
63 64 __all__ = ["auto_fetch_reconnect_urls", "set_reconnect_urls"] 65