awips2/cotsSource/org.apache.qpid/python/server010
root a02aeb236c Initial revision of AWIPS2 11.9.0-7p5
Former-commit-id: 06a8b51d6d [formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]
Former-commit-id: 9f19e3f712
2012-01-06 08:55:05 -06:00

72 lines
2 KiB
Python
Executable file

#!/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 qpid import delegates
from qpid.connection010 import Connection
from qpid.util import connect, listen
from qpid.spec010 import load
from qpid.session import Client
from qpid.datatypes import Message
from qpid.log import enable, DEBUG, WARN
import sys
if "-v" in sys.argv:
level = DEBUG
else:
level = WARN
enable("qpid", level)
spec = load("../specs/amqp.0-10.xml")
class Server:
def connection(self, connection):
return delegates.Server(connection, self.session)
def session(self, session):
session.auto_sync = False
return SessionDelegate(session)
class SessionDelegate(Client):
def __init__(self, session):
self.session = session
def queue_declare(self, qd):
print "Queue %s declared..." % qd.queue
def queue_query(self, qq):
return qq._type.result.type.new((qq.queue,), {})
def message_transfer(self, cmd, headers, body):
m = Message(body)
m.headers = headers
self.session.message_transfer(cmd.destination, cmd.accept_mode, cmd.acquire_mode, m)
def message_accept(self, messages):
print "ACCEPT %s" % messages
server = Server()
for s in listen("0.0.0.0", spec.port):
conn = Connection(s, spec, server.connection)
conn.start(5)