Hi chaps,
for info I'm (finally!!) really close to finishing my Java
implementation of the QMF2 API. It's pretty fully featured including
Subscriptions on the Agent class (my test Agent is the mystical
profitron too :-)) and also an emulation of Subscriptions on the console
side for the C++ broker ManagementAgent (which doesn't support
subscriptions) - that feature works by using the periodic broker
ManagementAgent data indication and wrapping it to look like a Subscription.
Anyway it's nearly finished bar some tarting up of the Javadoc and
tidying up the tests and demos. I'm going to try and make a concerted
push this weekend to finish it.
One of the demos is a Java port of qpid-config that uses pure QMF2 to
add/delete queues/bindings/exchanges, so with respect to QMF remote
method invocation, as a taster, the QpidConfig addQueue method looks
like this:
private void addQueue(String[] args)
{
if (args.length < 1)
{
usage();
}
Map properties = new HashMap();
for (String a : extraArguments)
{
String[] r = a.split("=");
String value = r.length == 2 ? r[1] : null;
properties.put(r[0], value);
}
if (_durable)
{
properties.put("durable", true);
properties.put(FILECOUNT, _fileCount);
properties.put(FILESIZE, _fileSize);
}
if (_maxQueueSize > 0)
{
properties.put(MAX_QUEUE_SIZE, _maxQueueSize);
}
if (_maxQueueCount > 0)
{
properties.put(MAX_QUEUE_COUNT, _maxQueueCount);
}
if (_limitPolicy.equals("reject"))
{
properties.put(POLICY_TYPE, "reject");
}
else if (_limitPolicy.equals("flow-to-disk"))
{
properties.put(POLICY_TYPE, "flow_to_disk");
}
else if (_limitPolicy.equals("ring"))
{
properties.put(POLICY_TYPE, "ring");
}
else if (_limitPolicy.equals("ring-strict"))
{
properties.put(POLICY_TYPE, "ring_strict");
}
if (_clusterDurable)
{
properties.put(CLUSTER_DURABLE, 1l);
}
if (_order.equals("lvq"))
{
properties.put(LVQ, 1l);
}
else if (_order.equals("lvq-no-browse"))
{
properties.put(LVQNB, 1l);
}
if (_eventGeneration > 0)
{
properties.put(QUEUE_EVENT_GENERATION, _eventGeneration);
}
if (_altExchange != null)
{
properties.put("alternate-exchange", _altExchange);
}
if (_flowStopSize > 0)
{
properties.put(FLOW_STOP_SIZE, _flowStopSize);
}
if (_flowResumeSize > 0)
{
properties.put(FLOW_RESUME_SIZE, _flowResumeSize);
}
if (_flowStopCount > 0)
{
properties.put(FLOW_STOP_COUNT, _flowStopCount);
}
if (_flowResumeCount > 0)
{
properties.put(FLOW_RESUME_COUNT, _flowResumeCount);
}
QmfData arguments = new QmfData();
arguments.setStringValue("type", "queue");
arguments.setStringValue("name", args[0]);
arguments.setValue("properties", properties);
try
{
_broker.invokeMethod("create", arguments);
}
catch (QmfException e)
{
System.out.println(e.getMessage());
}
// passive queue creation not implemented yet (not sure how to
do it using QMF2)
}
Ken Giusti wrote:
Yes - equivalent examples for a python agent and client can be found in
cpp/bindings/qmf2/examples/python directory.
-K
----- Original Message -----
Would it be possible to write an agent in python also?
Daryoush
On Wed, Nov 9, 2011 at 2:01 PM, Ken Giusti <[email protected]>
wrote:
Hi Daryoush,
There are some basic examples in
qpid/cpp/bindings/qmf2/examples/cpp/
directory.
See:
agent.cpp - an example agent that exposes some method calls (like
"echo").
list_agents.cpp - an example console that listens for agents
connecting to
a broker.
Unfortunately, there are no examples of making method calls (!)
I've hacked a quick example of calling the "echo" method exported
by
agent.cpp. If you apply the patch below to list_agents.cpp
(trunk), it
will attempt to call the "echo" method.
Fire off a broker (qpidd), start the agent.cpp executable (leave it
running), then run the modified list_agents.cpp.
didn't test it very well, but it should give you an idea...
Index: list_agents.cpp
===================================================================
--- list_agents.cpp (revision 1199840)
+++ list_agents.cpp (working copy)
@@ -21,6 +21,9 @@
#include <qpid/messaging/Duration.h>
#include <qmf/ConsoleSession.h>
#include <qmf/ConsoleEvent.h>
+#include <qmf/Query.h>
+#include <qmf/Data.h>
+#include <qmf/DataAddr.h>
#include <qmf/Agent.h>
#include <qpid/types/Variant.h>
#include <string>
@@ -60,6 +63,40 @@
if (event.getAgent().getName() ==
session.getConnectedBrokerAgent().getName())
extra = " [Connected Broker]";
cout << "Agent Added: " <<
event.getAgent().getName() <<
extra << endl;
+ // find the "Profitron" agent
+ if (event.getAgent().getVendor() ==
"profitron.com") {
+ Agent myAgent = event.getAgent();
+ // query the agent for its schema
+ ConsoleEvent schemaInfo =
event.getAgent().querySchema();
+ // cout << "Schema Count: " <<
schemaInfo.getSchemaIdCount() << endl;
+ // Find the Schema identifier for the
"control"
class...
+ for (int i = 0; i <
schemaInfo.getSchemaIdCount();
++i) {
+ SchemaId sid = schemaInfo.getSchemaId(i);
+ // cout << "SchemaId: " <<
sid.getPackageName()
<< ":" << sid.getName() << ":" << sid.getHash() << endl;
+ if (sid.getName() == "control") {
+ // now query the agent for all the
"control"
objects - there is only one in this example
+ Query q(QUERY_OBJECT_ID, sid);
+ ConsoleEvent obj = myAgent.query(q);
+ // cout << "Query returned=" <<
obj.getType()
<< endl;
+ // "control" is a singleton, so
getDataCount() returns 1 below
+ for (int j = 0; j <
obj.getDataCount(); ++j) {
+ // cout << "addr= " <<
obj.getData(j).getAddr().asMap() << endl;
+
+ // get the address of the object,
so we
can call methods against it:
+ DataAddr myObjId =
obj.getData(j).getAddr();
+ // arguments to "echo" method
+ Variant::Map args;
+ Variant::Map map_data;
+ map_data["hello"] =
Variant("world!");
+ args["sequence"] = Variant(1);
+ args["map"] = map_data;
+ // invoke the method synchronously
+ ConsoleEvent rc =
event.getAgent().callMethod("echo", args, myObjId);
+ cout << "results=" <<
rc.getArguments()
<< endl;
+ }
+ }
+ }
+ }
}
if (event.getType() == CONSOLE_AGENT_DEL) {
if (event.getAgentDelReason() == AGENT_DEL_AGED)
----- Original Message -----
I need to find out of if Qpid's QMF would work for a simple RPC
application that I need to develop. Any samples or tutorials
showing
the agent requirements would be greatly appreciated.
Thanks
Daryoush
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]
--
Daryoush
Weblog: http://onfp.blogspot.com/
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]