qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pavel Moravec <pmora...@redhat.com>
Subject Re: python QMF synchronization
Date Wed, 21 Mar 2012 11:35:08 GMT
.. and now also for python client (that I overlooked in email subject):


conn = Connection(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": "delete",
             "_arguments": {"type":"queue", "name":queue_name}
            } 
  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=30)
    if response.properties['x-amqp-0-10.app-id'] == 'qmf2':
      if response.properties['qmf.opcode'] == '_method_response':
        print "Response:"
	print 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()



----- Original Message -----
> From: "Pavel Moravec" <pmoravec@redhat.com>
> To: users@qpid.apache.org
> Sent: Wednesday, March 21, 2012 12:33:28 PM
> Subject: Re: python QMF synchronization
> 
> Hi Martin,
> you can set up ReplyTo address where qpid shall send its response.
> I.e. something like C++ code below (that invokes queue deletion and
> fetches response in 30seconds limit):
> 
>     Connection connection(url);
>     try {
>         connection.open();
>         Session session = connection.createSession();
>         Sender sender =
>         session.createSender("qmf.default.direct/broker");
>         Address responseQueue("#reply-queue; {create:always,
>         node:{x-declare:{auto-delete:true}}}");
>         Receiver receiver = session.createReceiver(responseQueue);
> 
>         Message message;
>         Variant::Map content;
> 	Variant::Map OID;
> 	Variant::Map arguments;
> 	OID["_object_name"] = "org.apache.qpid.broker:broker:amqp-broker";
> 	arguments["type"] = "queue";
> 	arguments["name"] = queue_name;
> 
>         content["_object_id"] = OID;
>         content["_method_name"] = "delete";
>         content["_arguments"] = arguments;
> 
>         encode(content, message);
> 	message.setReplyTo(responseQueue);
> 	message.setProperty("x-amqp-0-10.app-id", "qmf2");
> 	message.setProperty("qmf.opcode", "_method_request");
> 
>         sender.send(message, true);
> 
> 	Message response;
> 	if (receiver.fetch(response,qpid::messaging::Duration(30000)) ==
> 	true)
> 	{
> 		qpid::types::Variant::Map recv_props = response.getProperties();
> 		if (recv_props["x-amqp-0-10.app-id"] == "qmf2")
> 			if (recv_props["qmf.opcode"] == "_method_response")
> 				std::cout << "Response: OK" << std::endl;
> 			else if (recv_props["qmf.opcode"] == "_exception")
> 				std::cerr << "Error: " << response.getContent() << std::endl;
> 			else
> 				std::cerr << "Invalid response received!" << std::endl;
> 		else
> 			std::cerr << "Invalid response not of qmf2 type received!" <<
> 			std::endl;
> 	}
> 	else
> 		std::cout << "Timeout: No response received within 30 seconds!" <<
> 		std::endl;
> 
>         connection.close();
>         return 0;
>     } catch(const std::exception& error) {
>         std::cout << error.what() << std::endl;
>         connection.close();
>     }
> 
> Kind regards,
> Pavel
> 
> 
> 
> ----- Original Message -----
> > From: "MartiN BeneŇ°" <martinbenesh@gmail.com>
> > To: "users" <users@qpid.apache.org>
> > Sent: Wednesday, March 21, 2012 12:26:59 PM
> > Subject: python QMF synchronization
> >
> > Hi,
> > I cannot find information about qmf synchronization. Or is every
> > call
> > synchronous?
> > For instance if I purge a queue: queue.purge(0)
> > how can i tell it was done?
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Mime
View raw message