9.7. コマンドの作成
QMF create コマンドは 5 つの引数を取ります。
- type
- 作成するオブジェクトのタイプ。これはキュー、交換、またはバインディングになります。
- Name
- 作成されるオブジェクトの名前。キューや交換の
name
引数は単一の値です。たとえば、という名前のキューは name 引数をその値の文字列にmy-queue
設定します。バインディングの名前では、パターンの exchange/queue/key を使用します。たとえば、: はamq.topic/my-queue/my-key
バインディングキーmy-queue
との交換amq.topic
と交換を指定しますmy-key
。 - properties
- 作成するオブジェクトの特定のプロパティー、値はネストされたマップです。
- Strict
- 厳密な引数は、現在無視されるブール値を取ります。この値は、認識されないプロパティーが指定されている場合にコマンドが失敗するかどうかを示します。
- auto_delete_timeout
- オプション。最初に自動削除キューを宣言する際に指定する場合は、削除が実行される遅延を秒単位で指定します。注記: 削除の対象となり、遅延が期限切れになる前にキューが再宣言される場合、キューは削除されません。
以下のコード例では QMF を使用してという名前のキューを作成し
my-queue
ます。この例で my-queue
は、10 秒後に自動削除するように設定されています。
- python
conn = Connection(opts.broker) try: conn.open() ssn = conn.session() snd = ssn.sender("qmf.default.direct/broker") reply_to = "reply-queue; {create:always, node:{x-declare:{auto-delete:true}}}" rcv = ssn.receiver(reply_to) content = { "_object_id": {"_object_name": "org.apache.qpid.broker:broker:amqp-broker"}, "_method_name": "create", "_arguments": {"type":"queue", "name":"my-queue", "properties":{"auto-delete":True, "qpid.auto_delete_timeout":10}} } request = Message(reply_to=reply_to, content=content) request.properties["x-amqp-0-10.app-id"] = "qmf2" request.properties["qmf.opcode"] = "_method_request" snd.send(request) try: response = rcv.fetch(timeout=opts.timeout) if response.properties['x-amqp-0-10.app-id'] == 'qmf2': if response.properties['qmf.opcode'] == '_method_response': return response.content['_arguments'] elif response.properties['qmf.opcode'] == '_exception': raise Exception("Error: %s" % response.content['_values']) else: raise Exception("Invalid response received, unexpected opcode: %s" % m) else: raise Exception("Invalid response received, not a qmfv2 method: %s" % m) except Empty: print "No response received!" except Exception, e: print e except ReceiverError, e: print e except KeyboardInterrupt: pass conn.close()